Skip to content

Calling the API

Create the TikTokShop client, call operations by API area, work with many shops, and handle 64-bit IDs in TypeScript.

TikTokShop is the API client. Each request it sends gets the following automatically:

  • the app_key, timestamp and sign query parameters;
  • your access token, in the x-tts-access-token header;
  • shop_cipher, on the operations that need one.
import { TikTokShop } from 'tiktok-shop-api';
const client = new TikTokShop({
appKey: process.env.TTS_APP_KEY!,
appSecret: process.env.TTS_APP_SECRET!,
accessToken: tokens.accessToken,
});
// Find the shop cipher
const shops = await client.authorization.getAuthorizedShops();
const shopCipher = shops.data?.shops?.[0]?.cipher;
const seller = client.withShop({ accessToken: tokens.accessToken, shopCipher });
const orders = await seller.orders.getOrderList({ pageSize: 20 });

One property per API area hangs off the client, matching the spec’s tags:

PropertyArea
affiliateCreator, affiliatePartner, affiliateSellerAffiliate creator, partner and seller
analyticsAnalytics
authorizationAuthorization, including getAuthorizedShops
customerEngagement, customerServiceCustomer engagement and customer service
eventEvent (webhook subscriptions)
financeFinance
fulfilledByTikTokFulfilled by TikTok (FBT)
fulfillment, logisticsFulfillment and logistics
orders, products, promotionOrders, products and promotion
returnAndRefundReturn and refund
seller, supplyChain, toolsSeller, supply chain and tools

Each method takes one object with the operation’s parameters and request body, and resolves with the response envelope (code, message, requestId, data). Method and parameter names follow the API reference, in camel case.

withShop returns a client for another shop. It shares the HTTP client and your app credentials, so you can keep one per shop:

const shopA = client.withShop({ accessToken: tokenA, shopCipher: cipherA });
const shopB = client.withShop({ accessToken: tokenB, shopCipher: cipherB });

TikTok Shop IDs (shop_id, order_id, product_id, …) are 64-bit integers, which JavaScript numbers cannot hold exactly. This client reads them as strings in every response and webhook, and sends them back as the numbers TikTok expects. For example, 7494049642642441621 stays "7494049642642441621".

OptionMeaning
appKey, appSecretYour app’s credentials.
accessTokenThe seller’s access token, sent in x-tts-access-token.
shopCipherThe shop cipher added to operations that need one.
baseUrlThe API host, an origin such as https://host:8443 with no path prefix: signing and shop-cipher matching use the request path. Defaults to https://open-api.tiktokglobalshop.com.
timeoutMsPer-request timeout. Defaults to 30 seconds (DEFAULT_TIMEOUT_MS); 0 means no limit.
fetchAn HTTP client override, defaulting to the global fetch.

The default client never follows a redirect. A 3xx reply is thrown as a TikTokShopError whose code and httpStatus are the status, so the access token is never forwarded to another host. A fetch you supply keeps its own redirect policy.

Some operations are GET requests with a JSON body, which fetch refuses. The client sends those with node:http or node:https instead.

Requests carry the User-Agent tiktok-shop-api-typescript/<version>, exported as USER_AGENT. The signing functions are exported too (sign, stringToSign and requiresShopCipher), for checking a signature by hand.