Skip to content
Last updated

Sync

E-commerce and catalog MiniApps use the top-level sync block for bulk import (initial and scheduled sync) and realtime webhook handlers that share the same field-mapping vocabulary.

Use sync when your integration must keep orders, customers, products, or carts aligned between an external platform and Karzoun — not just fire automation triggers.

See also

Structure

sync: {
  baseUrl: 'https://api.example.com/v2',
  headers: {
    Authorization: 'Bearer [[accessToken]]',
    'Content-Type': 'application/json',
  },
  syncConfiguration: {
    enabled: true,
    batchSize: 200,
    rateLimitPerSecond: 10,
    timeout: 30000,
  },
  resources: {
    products: { /* ... */ },
    customers: { /* ... */ },
    orders: { /* ... */ },
  },
  webhooks: {
    handlers: {
      'order.created': { /* same mapping style as resources */ },
    },
  },
},
BlockPurpose
baseUrl + headersShared prefix for all sync HTTP calls (supports [[accessToken]])
syncConfigurationBatch size, rate limits, timeouts for bulk jobs
resources.*Paginated list/detail endpoints + apiMapping into Karzoun content types
webhooks.handlersRealtime create/update mappings keyed by event name

Resource definition

Each key under resources defines one importable entity:

products: {
  name: 'products',
  displayName: 'Products',
  description: 'Sync products from your platform',
  contentType: 'core:product',
  expandDetails: true,
  endpoints: {
    list: { url: '/products', method: 'GET' },
    details: { url: '/products/{id}', method: 'GET' },
  },
  pagination: {
    paramName: 'per_page',
    defaultLimit: 60,
    maxLimit: 1000,
  },
  responseMapping: {
    dataProperty: 'data',
    totalProperty: 'pagination.total',
  },
  apiMapping: {
    name: 'name',
    code: { path: 'id', transform: 'toString' },
    unitPrice: { paths: ['price.amount', 'regular_price.amount'], transform: 'coalesce' },
    // ...
  },
  icon: 'package',
},
FieldDescription
contentTypeTarget Karzoun entity (core:product, core:customer, ecommerce:orders, …)
endpoints.listPaginated collection fetch
endpoints.detailsOptional per-record enrichment when expandDetails: true
apiMappingField mapping rules (paths, transforms, literals) — same schema as webhook handlers

Mapping transforms

Common transforms used in apiMapping:

TransformUse
toStringCoerce IDs to strings
toNumberOrNullNumeric fields with null fallback
coalesceFirst non-empty path in paths array
compute + fnPlatform-specific helpers (document custom fn names in your submission)
mapItemsLine items in orders/carts
joinCodesDiscount/coupon code arrays

Webhook handlers under sync

Realtime events use sync.webhooks.handlers (preferred over legacy webhook.ecommerce):

sync: {
  // ... resources ...
  webhooks: {
    handlers: {
      'order.created': {
        recordType: 'order',
        operation: 'create',
        mapping: {
          code: '$.data.id',
          orderNumber: '$.data.reference_id',
          status: '$.data.status.name',
          totalAmount: '$.data.amounts.total.amount',
          items: { path: '$.data.items', transform: 'mapItems' },
        },
      },
      'order.status.updated': {
        recordType: 'order',
        operation: 'update',
        mapping: {
          code: '$.data.id',
          status: '$.data.status.name',
        },
      },
    },
  },
},

Pair every handler event with a matching trigger so automations can react after sync processing.

Bulk sync lifecycle

  1. Tenant installs MiniApp and completes OAuth / API key setup.
  2. Karzoun runs enabled resources according to syncConfiguration.
  3. Ongoing changes arrive via provider webhooks → sync.webhooks.handlers.
  4. Rate limits and batch sizes protect both your API and Karzoun workers.

Submission checklist

  • List + detail endpoints tested with sandbox credentials
  • apiMapping covers required fields for each contentType
  • Webhook handler events match triggers[].event strings exactly
  • Pagination responseMapping matches your provider's JSON shape
  • Sample payloads included in your submission package