快工助手跨境电商知识与商机助手

Get widget token

TikTok Shop 官方资料 · TikTok Shop Partner Center 开发者文档 · 适合开发者

stable本次发布有变化全部展示

来自 TikTok Shop 官方资料快照 ·

打开官方原文 ↗
  1. 当前资料结构化阅读页
  2. 固定快照已留存,可追溯
  3. 官方原文可核对
查看技术与溯源信息
平台 / profile
TikTok Shop / profile.tiktok.docs_api
语言
en-US
发布版本
cn-20260909-2
标签
zhuge/sourceplatform/tiktok_shopaudience/developercategory/api_doctopic/compliancetopic/developer

资料正文

§1 Overview

Use Get Widget Token to generate a short-lived widget_token for TikTok Shop Widget SDK integration. The token flow is:

StepActorToken or interfacePurpose
1Seller and developer backendaccess_tokenThe seller authorizes the app, and the developer backend obtains an access token through the TikTok Shop authorization flow.
2Developer backendGET /authorization/202401/widget_tokenThe backend calls this Open API with the signed query parameters and x-tts-access-token header.
3TikTok Shop Open APIwidget_tokenThe API returns a short-lived widget token. It usually expires in about 5 minutes.
4Developer backend and frontendDeveloper-owned token endpoint, for example /api/widget-tokenThe backend returns the widget token to the frontend. Do not expose the seller access_token or App Secret to frontend code.
5Frontend Widget SDKgetToken callbackThe frontend SDK uses the widget token to load and call widget services.

access_token and widget_token are different credentials. The access_token is used by the developer backend to call TikTok Shop Open APIs. The widget_token is a short-lived token passed to the Widget SDK.

#

§2 API endpoint

ItemValue
API nameGet Widget Token
API version202401
Hosthttps://open-api.tiktokglobalshop.com
MethodGET
Path/authorization/202401/widget_token
Request bodyNone
AuthenticationSigned common query parameters plus x-tts-access-token header
#

§3 Domain and interface scope

Use the correct domain or interface for each part of the integration.

Domain or interfaceUse forCalled by
https://open-api.tiktokglobalshop.comTikTok Shop Open API resource server. Use this host to call GET /authorization/202401/widget_token.Developer backend
https://partner.tiktokshop.com and https://partner.us.tiktokshop.comPartner Center, documentation, app configuration, seller authorization entry, API Testing Tool, and support tickets.Developers in browser / authorization flows
/api/v1/seller/widget/getWidget SDK-side interface mentioned in the Widget SDK guide and SDK troubleshooting. Do not use it as the Open API endpoint for generating a widget token.Widget runtime / SDK-side service
#

§4 Request headers

NameTypeRequiredDescription
x-tts-access-tokenstringYesThe seller access token obtained through the TikTok Shop authorization flow. This token must belong to the seller/shop that will use the widget.
Content-TypestringYesUse application/json.
#

§5 Query parameters

This API has no required business request parameters. Use only the common signed query parameters for normal calls.

NameTypeRequiredDescription
app_keystringYesThe unique key assigned to your app in Partner Center.
timestampint64YesUnix timestamp in seconds. The same timestamp value must be used when generating sign.
signstringYesSignature generated from the request path, query parameters, request body if any, and App Secret. See Sign your API request.
shop_idint64NoOptional in the API schema, but not needed for normal calls. The seller/shop context is resolved from x-tts-access-token. Do not pass it unless TikTok Shop support or the API Testing Tool explicitly instructs you to do so.
#

§6 Sample request

curl --location --request GET 'https://open-api.tiktokglobalshop.com/authorization/202401/widget_token?app_key=<your_app_key>&timestamp=<unix_timestamp>&sign=<signature>' \
  --header 'Content-Type: application/json' \
  --header 'x-tts-access-token: <seller_access_token>'
#

§7 Response parameters

FieldTypeRequiredDescription
codeint32YesThe success or failure status code returned in the API response.
messagestringYesSuccess message or failure reason.
request_idstringYesRequest log ID. Include this value when contacting support.
dataobjectNoResponse data.
data.widget_tokenobjectNoWidget token information.
data.widget_token.tokenstringNoThe short-lived token passed to the Widget SDK.
data.widget_token.expire_atint64NoExpiration timestamp of the widget token. The widget token usually expires in about 5 minutes.
#

§8 Response sample

{
  "code": 0,
  "data": {
    "widget_token": {
      "token": "<widget_token>",
      "expire_at": 1703100448
    }
  },
  "message": "Success",
  "request_id": "202203070749000101890810281E8C70B7"
}
#

§9 Frontend SDK handoff

Your frontend should call your own backend endpoint to get the widget token. The backend should call TikTok Shop Open API and return only the short-lived widget token information.

async function getWidgetToken() {
  const response = await fetch('/api/widget-token', {
    method: 'GET',
    credentials: 'include'
  });
  const result = await response.json();

  if (result.code !== 0) {
    throw new Error(result.message || 'Failed to get widget token');
  }

  return result.data.widget_token;
}

When configuring @tiktokshop/widget-kit or @tiktokshop/widget-kit-react, pass this function to the SDK getToken field. The frontend SDK should receive a value with token and expire_at.

#

§10 Error codes

Error codeError messageMeaningRecommended action
98001001internal errorThe service failed to retrieve the authorization or shop context.Retry with exponential backoff. If the error persists, contact TikTok Shop support with request_id, app key, market, timestamp, and the full response.
98001004Invalid paramA required query parameter or header is missing, invalid, or inconsistent with the generated signature.Check app_key, timestamp, sign, x-tts-access-token, Content-Type, endpoint path, and API version. Regenerate the signature after confirming the exact request URL.
13002013Seller does not existThe access token does not map to a valid authorized seller/shop for this API call.Confirm that the seller has authorized the app, use the correct seller access_token, refresh or re-authorize if needed, and verify the authorized shop mapping with Get Authorized Shops.

Widget SDK errors are handled separately from this Open API response. For example, /api/v1/seller/widget/get errors such as domain whitelist mismatch, expired widget token, invalid widget token, app key mismatch, or shop/region mismatch should be debugged in the Widget SDK integration layer.

#

§11 Testing

You can test this API in the API Testing Tool or with a command-line client such as cURL. Before testing:

  1. Confirm that the app is created and the App Key is correct.
  2. Complete seller authorization and obtain a valid seller access_token.
  3. Generate the sign value using the exact request path and query parameters.
  4. Pass x-tts-access-token in the request header.
  5. After receiving widget_token, verify that your frontend SDK getToken callback returns the object containing token and expire_at.
#