Connect TikTok with Shopify
A technical guide for engineers building production-grade TikTok to Shopify integrations, covering Catalog Sync, Events API (CAPI), and webhook orchestration.
Implementation Guide
Overview
Integrating TikTok with Shopify at an enterprise level transcends simple pixel placement. For technical teams, this integration represents a high-throughput data synchronization challenge involving the TikTok Marketing API (specifically the Events API and Catalog API) and the Shopify Admin REST/GraphQL APIs. The primary objective is to create a bidirectional flow where product catalogs are synchronized in near real-time, and downstream conversion events are fed back into TikTok’s attribution engine via server-side signals to bypass the limitations of client-side tracking (ITP, ATT, and ad-blockers).
In a production environment, this architecture must account for high-velocity flash sales, where Shopify's webhook volume can spike to thousands of events per second, and TikTok’s ingestion limits. Architects must implement a robust middleware layer—typically utilizing a message broker like RabbitMQ or Amazon SQS—to decouple the ingestion of Shopify webhooks from the processing and transmission of data to TikTok. This guide focuses on the implementation of the TikTok Events API (CAPI) for server-side attribution and the TikTok Catalog API for automated product synchronization, ensuring data consistency and high match rates through advanced hashing and identity resolution.
Core Prerequisites
Before initiating development, ensure the following credentials and configurations are established within both ecosystems. For TikTok, you require a TikTok for Business account and a Developer App registered within the TikTok Marketing API portal. The app must be approved for the 'Marketing API' and 'Events API' scopes. Specifically, you will need the Developer Token (Permanent or Long-lived), the Pixel ID (used as the pixel_code in API calls), and the App ID for OAuth 2.0 flows.
On the Shopify side, a Custom App or a Public App must be created within the Shopify Admin. The integration requires the following OAuth scopes at a minimum: read_products, read_inventory, read_orders, and read_customers. If you are implementing TikTok Shop (Direct Integration), you will also require write_orders and write_fulfillment_orders. Ensure the Shopify API version is pinned to a stable release (e.g., 2024-04).
From a networking perspective, your middleware must support TLS 1.2+ and be capable of handling TikTok’s requirement for SHA-256 hashing on all PII (Personally Identifiable Information) before transmission. You will also need a dedicated endpoint to handle Shopify's X-Shopify-Hmac-Sha256 signature verification to ensure the integrity of incoming webhooks.
Top Enterprise Use Cases
1. Server-Side Events API (CAPI) for Full-Funnel Attribution
Client-side pixels are increasingly unreliable due to browser privacy restrictions. Enterprise integrations leverage the TikTok Events API to send conversion data directly from the server. This includes AddToCart, InitiateCheckout, and CompletePayment events. By sending server-side events, engineers can include additional metadata such as external_id, hashed_email, and hashed_phone_number, which significantly increases the match rate on TikTok’s side. This use case requires a deduplication strategy where both the browser pixel and CAPI send the same event_id, allowing TikTok to discard redundant signals while filling the gaps left by blocked browser scripts.
2. High-Frequency Catalog Synchronization
For merchants with dynamic pricing or volatile inventory levels, manual CSV uploads are insufficient. The TikTok Catalog API allows for automated batch updates of product data. This integration ensures that the TikTok Shop or TikTok Dynamic Showcase Ads (DSA) always reflect the current state of the Shopify store. This involves mapping Shopify’s product_variant objects to TikTok’s catalog schema, handling currency conversions, and managing multi-language descriptions. A robust implementation uses Shopify’s Bulk Operation API for initial seeding and the products/update webhook for incremental synchronization.
3. TikTok Shop Order Orchestration
When TikTok acts as the storefront (TikTok Shop), the integration must treat Shopify as the System of Record (SoR) for inventory and fulfillment. This requires a complex bidirectional sync: pulling orders from TikTok’s Order API, injecting them into Shopify via the Orders API, and then pushing fulfillment status and tracking numbers back to TikTok once the warehouse processes the shipment. This pattern must handle conflict resolution, such as when an item goes out of stock on Shopify simultaneously with a purchase on TikTok.
Step-by-Step Implementation Guide
Phase 1: The OAuth 2.0 Handshake
TikTok uses a standard OAuth 2.0 flow. Your application must redirect the user to TikTok’s authorization URL. Once the user grants permission, TikTok redirects back with an auth_code. Exchange this code for an access_token and a refresh_token.
// POST https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/
{
"app_id": "7123456789012345678",
"secret": "your_app_secret",
"auth_code": "CODE_FROM_REDIRECT",
"grant_type": "auth_code"
}
Store the access_token securely (e.g., AWS Secrets Manager). Note that TikTok access tokens typically expire in 24 hours, while refresh tokens last for 1 year. Implement a background worker to refresh tokens before expiration to prevent service interruption.
Phase 2: Implementing the Events API (CAPI)
When a transaction occurs on Shopify, your server receives an orders/paid webhook. You must transform this payload into the TikTok Events API format. Crucially, all PII must be normalized (lowercase, trimmed) and hashed using SHA-256.
Example TikTok Events API Payload:
{
"pixel_code": "C1234567890ABC",
"event": "CompletePayment",
"event_id": "shp_12345_98765",
"timestamp": "2023-10-27T10:00:00Z",
"context": {
"ad": {
"callback": "TT_AD_CALLBACK_ID"
},
"user": {
"external_id": "f528764d624db129b32c21fbca0cb8d6",
"emails": ["7b16454435293304033a173f50547c12b63b4df2143db072127a0f7ec5682ed0"],
"phone_numbers": ["e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"]
},
"page": {
"url": "https://mystore.com/checkout/success"
}
},
"properties": {
"content_type": "product",
"contents": [
{
"content_id": "SKU-12345",
"content_name": "Technical Running Shoes",
"quantity": 1,
"price": 120.00
}
],
"currency": "USD",
"value": 120.00
}
}
Phase 3: Catalog Synchronization via Batch API
To sync products, use the TikTok Catalog API. For large inventories, avoid individual API calls. Instead, use the /catalog/item/batch/ endpoint which supports up to 1,000 items per request.
Shopify Product to TikTok Mapping Logic:
- Fetch product from Shopify:
GET /admin/api/2024-04/products/{id}.json. - Map
variants[0].skuto TikTokitem_group_id. - Map
body_html(stripped of tags) todescription. - Ensure
images[0].srcis a publicly accessible URL.
TikTok Batch Request:
{
"catalog_id": "7234567890123456789",
"items": [
{
"item_id": "SKU-12345",
"item_group_id": "GRP-999",
"title": "Technical Running Shoes",
"description": "High-performance footwear for engineers.",
"availability": "in stock",
"condition": "new",
"price": "120.00",
"currency": "USD",
"link": "https://mystore.com/products/running-shoes",
"image_link": "https://cdn.shopify.com/s/files/1/image.jpg"
}
]
}
Phase 4: Idempotency and Retry Strategy
Network partitions and rate limits are inevitable. For the Events API, TikTok provides an event_id field. Use the Shopify Order ID or a combination of the Checkout ID and timestamp as the event_id. This allows TikTok to perform deduplication if the same event is retried.
Implement exponential backoff with jitter for all 429 (Too Many Requests) and 5xx status codes. For Shopify, monitor the X-Shopify-Shop-Api-Call-Limit header (e.g., 38/40). If the leaky bucket is near capacity, throttle your outgoing requests. For TikTok, the Marketing API has various limits based on the endpoint (e.g., 10 queries per second for certain reporting endpoints), so implement a global rate limiter in your middleware.
Common Pitfalls & Troubleshooting
1. Data Normalization Failures
One of the most common reasons for low match rates in the Events API is improper PII hashing. TikTok expects emails to be trimmed of whitespace and converted to lowercase before SHA-256 hashing. If you hash " [email protected]" instead of "[email protected]", the hashes will not match TikTok's internal database, rendering the attribution data useless. Always validate your hashing utility against TikTok's provided test strings.
2. Webhook Sequencing and Race Conditions
Shopify webhooks are not guaranteed to arrive in order. An orders/updated webhook might arrive before an orders/create webhook. To handle this, use a versioning column in your database (e.g., updated_at from the Shopify payload). Only process the incoming webhook if its updated_at timestamp is greater than the one currently stored for that resource. This is critical for inventory sync to prevent overwriting a newer state with stale data.
3. TikTok API Versioning
TikTok iterates on its Marketing API rapidly. Version v1.3 is the current stable standard, but breaking changes can occur in minor releases. Always specify the version in the URL path. Monitor the TikTok Developer changelog for deprecation notices regarding specific fields in the properties object of the Events API.
4. Handling Shopify's API Limits
Shopify's REST API uses a leaky bucket algorithm. For high-volume stores, the standard 2 requests per second (RPS) is often insufficient. Consider upgrading the store to Shopify Plus to increase the limit to 40 RPS, or migrate your catalog sync logic to the GraphQL Admin API, which uses a cost-based throttling mechanism that is generally more efficient for complex, nested data fetches like product variants and metafields.
5. Asynchronous Processing and Dead Letter Queues (DLQ)
Never process the TikTok API call synchronously within the Shopify webhook listener. If TikTok's API is slow or down, it will cause the Shopify webhook to timeout, leading Shopify to retry and eventually disable your webhook subscription. Instead, acknowledge the webhook immediately with a 200 OK, push the payload to a queue, and have a separate worker process the TikTok integration. If an event fails after maximum retries, move it to a Dead Letter Queue for manual inspection and replay.
Need a different integration?
If you can't find the guide you need, submit a request and I'll add it to the publishing queue.
Request an integration →