Qeasy Cloud
Get Started

SQL Server and Marketing Cloud Purchase Order Integration: An End-to-End Workflow with 16 Strategies

· 系统管理员· Integration Solutions· 38 views· 4 min read
SQL Server汤臣倍健营销云营销云采购入库退货入库协议订单主数据联查

Scenario and Value

In the health-product and FMCG industries, brand owners typically use a marketing cloud to coordinate purchase agreements and orders across multiple distributors and brands, while internal ERP systems often rely on SQL Server for master data persistence and document landing. Three natural gaps exist between the marketing cloud and an on-premises SQL Server: inconsistent item coding schemes that require spid cross-referencing, gift and combo-pack batch numbers hidden in nested structures that are easy to drop during extraction, and three different document types — purchase receiving, sales returns, and agreement orders — each with distinct incremental fields and state machines, making unified scheduling error-prone.

Targeting the scenario above, this article presents an end-to-end workflow for 16 integration strategies at a retail enterprise, aiming to steadily land marketing-cloud procurement documents into SQL Server by organization and brand, while preloading item master data into the platform cache for downstream cross-reference.

Integration Architecture and Data Flow

The overall architecture has three layers: the marketing cloud API layer, the integration middleware (ETL/scheduler) layer, and the SQL Server persistence layer.

  • Marketing cloud layer: exposes three groups of endpoints for purchase receiving, sales returns, and new-version agreement orders.
  • Integration middleware layer: handles scheduling, field transformation, item code cross-reference, gift and combo-pack batch mapping, exception retry, and incremental watermark maintenance.
  • SQL Server layer: Inter_spzl_v acts as the item master source, gxkphz and gxkpmx serve as purchase and return header/detail landing tables, and Inter_ddmx is the single landing table for order details.

An implicit dependency exists between the master data strategy and the business strategies: Inter_spzl_v must run before or in parallel with the business strategies to populate the spid cache. The business strategies themselves have no hard dependencies, but a 1–2 minute stagger is recommended at the scheduling layer to avoid marketing cloud API rate limits.

Interface List

Strategy GroupSource PlatformTarget PlatformData ObjectSync Direction
Purchase receiving (A/D/E/F/G/H)Marketing cloud purInWarehsOrderSQL Server gxkphz/gxkpmxPurchase receiving documentMarketing cloud → SQL Server
Sales return (B/I/J/K)Marketing cloud saleReturnOrderSQL Server gxkphz/gxkpmxSales return documentMarketing cloud → SQL Server
New-version order (L/M/N/O/P)Marketing cloud order/honour/agreement/headerSQL Server Inter_ddmxAgreement orderMarketing cloud → SQL Server
Master data lookup (C)SQL Server Inter_spzl_vPlatform cacheItem masterSQL Server → Platform

Implementation Points

Master data preloading. Strategy C extracts item master data from Inter_spzl_v, uses lasttime as the incremental field, writes it into the platform cache, and is scheduled every 5 minutes across 8:00–22:00 to provide spbh2 → spid cross-reference capability for the business strategies.

Purchase receiving sync. The source endpoint is /erp/api/order/query/purInWarehsOrder; the target tables are gxkphz (header) and gxkpmx (detail). Incremental data is fetched using beginTime/endTime and timeType=1 on update time, with manual full-load support. Key transformations include: cross-referencing materialNumber against master data to obtain spid; pulling gift batch numbers from giftInfoList; and backfilling line numbers oSn in the script layer.

Sales return sync. The source endpoint is /erp/api/order/query/saleReturnOrder, landing into the same gxkphz and gxkpmx tables, with djlx distinguishing return documents. Note that the header does not carry consignee, address, or phone information; only document status and details are synchronized.

New-version order sync. The source endpoint is /api/openapi/v1/erp/order/honour/agreement/header, landing into Inter_ddmx, with incremental fields lastStartDt/lastEndDt. Combo-pack batch numbers must be pulled from the subItems array, orderStatus requires multi-state mapping, and nature=1 identifies the document as an order.

Scheduling strategy. Master data strategy runs every 5 minutes; purchase receiving every 2–3 minutes; sales returns every 6 minutes; new-version orders every 3–5 minutes. Staggering between business groups reduces the risk of marketing cloud API rate limits.

Best Practices

  • Item code mapping depends on master data running first. The spid cross-reference in business strategies relies on the platform cache. Ensure the master data strategy has executed at least once, otherwise nulls or fallbacks will appear.
  • Handle gift and combo-pack batches separately. Both giftInfoList and subItems are nested structures; explicitly flatten them in ETL scripts to avoid being swallowed by the header structure.
  • Run incremental and full load in different lanes. Incremental loads follow business fields; full loads are only used for initialization and data repair, and should be triggered manually on a weekly or as-needed basis to avoid duplicates or overwrites from concurrent runs.
  • Layer exception and retry policies by failure type. Configure different retry strategies for marketing cloud rate limits and SQL Server deadlocks: exponential backoff for rate limits, fast-fail then human intervention for deadlocks.
  • Isolate credentials and organization IDs. Connection strings, authentication information, and organization IDs must be stored in environment variables, never hard-coded in strategy scripts.
  • Stagger rather than run everything in parallel. Although the business strategies have no hard dependencies, running them at full parallelism can trigger rate limits. A 1–2 minute stagger is the more reliable approach.

This article focuses on the overall workflow and cross-strategy coordination design. Per-strategy field mappings, exception handling, and scheduling details can be found in the expert verification document and the dedicated design documents for each strategy group.

Original content. Please credit the source when reposting: /insights/solutions/sol-sql-server-p158a24-4991

Comments