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

Postman

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 Postman

Postman is a popular API platform for building and testing APIs. You can use Postman to accelerate TikTok Shop API testing and integration. For a first API request, follow the tutorial Call Get Authorized Shops. The endpoint used in this tutorial is documented in the API reference Get Authorized Shops. Use the tutorial page for the end-to-end walkthrough, and use the API reference page for the full endpoint schema.

#

§2 Download the Postman collection

We provide a ZIP file that contains a Postman collection and a set of environment variables. Fill in the environment variables, including app_key, app_secret, and auth_code, then call GET Access Token to obtain an API access token. The collection can then use the saved variables to call subsequent APIs. Download the Postman collection The original CDN path contains [[, which must be URL-encoded as %5B%5B. The encoded link above is the working download URL. Important: Do not commit, submit, or share any Postman collection, environment file, or script that contains a real App Secret. Use YOUR_APP_SECRET only as a placeholder in examples, and store the real app_secret only in a private Postman environment variable.

#

§3 Domain reference

This guide uses more than one TikTok Shop domain because each domain has a different purpose.

DomainPurposeExample in this guide
auth.tiktok-shops.comOAuth token APIs, including getting and refreshing access tokens.https://auth.tiktok-shops.com/api/v2/token/get
open-api.tiktokglobalshop.comTikTok Shop OpenAPI calls after you have an access token and request signature.https://open-api.tiktokglobalshop.com/authorization/202309/shops
partner.tiktokshop.com/docv2Developer documentation pages, tutorials, and API reference pages.Call Get Authorized Shops

For authorization entry URLs and market-specific authorization domains, refer to the Authorization guide.

#

§4 Step 1: Obtain an access token

This section walks through obtaining an access_token in Postman. For more information about access tokens, refresh tokens, and required parameters, refer to the Authorization guide. 1. Open a new request tab. Set the request method to GET and use this request URL:

https://auth.tiktok-shops.com/api/v2/token/get

Image 2. Add the query parameters.

ParameterValueRequiredNotes
app_key{{app_key}}YesYour app key from Partner Center.
app_secret{{app_secret}}YesStore this value in a private Postman environment variable. Do not hardcode it in scripts or share it in screenshots.
auth_code{{auth_code}}YesThe authorization code returned after authorization. Replace the sample value in the environment file.
grant_typeauthorized_codeYesThis value must be entered exactly as authorized_code. Do not change it to the standard OAuth spelling authorization_code.

Image 3. Send the request. Press Send next to the request URL. If successful, the response should resemble the following: Image 4. Save token variables. The downloaded collection can save token values automatically. If you configure the request manually, add a Postman Tests script like this:

var json = pm.response.json();

if (json && json.data) {
    pm.environment.set("access_token", json.data.access_token);
    pm.environment.set("refresh_token", json.data.refresh_token);
}

For token lifecycle details and refresh-token usage, refer to Generate a test access token.

#

§5 Step 2: Set common parameters

This section walks through setting up common parameters to call Get Authorized Shops. 1. Open a new request tab. Set the request method to GET and use this request URL:

https://open-api.tiktokglobalshop.com/authorization/202309/shops

Image 2. Add the query parameters.

ParameterValueRequiredNotes
app_key{{app_key}}YesYour app key from Partner Center.
timestamp{{timestamp}}YesGenerated by the Pre-request Script in Step 3. Use Unix epoch seconds.
sign{{sign}}YesGenerated by the Pre-request Script in Step 3.

Image Important: Set sign to {{sign}} and timestamp to {{timestamp}}. If the timestamp is too old, regenerate both timestamp and sign before sending the request. 3. Add the headers.

HeaderValueRequiredNotes
Content-Typeapplication/jsonYesRequired by the API.
x-tts-access-token{{access_token}}YesThe access token obtained in Step 1.

Image If you press Send before generating sign and timestamp, the API returns a signature error. Continue to Step 3 to automate request signing in Postman.

#

§6 Step 3: Request signature

Calling TikTok Shop OpenAPI requires a request signature. Postman can generate the signature automatically in the Pre-request Script section. For the canonical signing rule, refer to Sign your API request. Important: Do not hardcode a real App Secret in the Pre-request Script. Use YOUR_APP_SECRET only as a placeholder in examples. Do not log the signing string, because it contains the App Secret. Set app_secret in your private Postman environment instead. 1. Set the required environment variables.

VariableValueRequiredNotes
app_secretYour App SecretYesUsed as the HMAC key. Keep it private.
timestampGenerated by scriptYesThe script sets this variable automatically.
signGenerated by scriptYesThe script sets this variable automatically.

2. Add this JavaScript Pre-request Script.

function objKeySort(obj) {
    var newKey = Object.keys(obj).sort();
    var newObj = {};
    for (var i = 0; i < newKey.length; i++) {
        newObj[newKey[i]] = obj[newKey[i]];
    }
    return newObj;
}

function getEnvVar(k) {
    var v = pm.variables.get(k);
    if (v != null) {
        return v;
    }
    v = pm.environment.get(k);
    if (v != null) {
        return v;
    }
    v = pm.collectionVariables.get(k);
    if (v != null) {
        return v;
    }
    v = pm.globals.get(k);
    if (v != null) {
        return v;
    }
    return null;
}

function interpolateVar(value) {
    if (value == null) {
        return "";
    }
    const { Property } = require("postman-collection");
    return Property.replaceSubstitutions(String(value), pm.variables.toObject());
}

function getRequestBody() {
    if (!pm.request.body) {
        return "";
    }

    if (pm.request.body.mode === "raw" && pm.request.body.raw) {
        return interpolateVar(pm.request.body.raw);
    }

    return "";
}

var secret = getEnvVar("app_secret");
if (!secret || secret === "YOUR_APP_SECRET") {
    throw new Error("Set app_secret in your Postman environment. Do not hardcode a real App Secret in the script.");
}

var ts = Math.floor(Date.now() / 1000).toString();
pm.variables.set("timestamp", ts);

function calSign(secret) {
    var queryParam = pm.request.url.query ? pm.request.url.query.members : [];
    var param = {};

    for (var i = 0; i < queryParam.length; i++) {
        var item = queryParam[i];
        if (item.disabled) {
            continue;
        }

        var value;
        if (item.key === "timestamp") {
            value = ts;
        } else {
            value = item.value;
            if (value == null || value === "{{" + item.key + "}}") {
                value = getEnvVar(item.key);
            }
        }

        param[item.key] = interpolateVar(value);
    }

    delete param.sign;
    delete param.access_token;

    var sortedObj = objKeySort(param);
    var signstring = secret + pm.request.url.getPath();
    for (var key in sortedObj) {
        signstring += key + sortedObj[key];
    }
    signstring += getRequestBody() + secret;

    return CryptoJS.HmacSHA256(signstring, secret).toString(CryptoJS.enc.Hex);
}

pm.variables.set("sign", calSign(secret));

For GET /authorization/202309/shops, the request body is empty. For APIs with a JSON request body, set the body to raw JSON before sending the request so the script can include the raw body in the signing string. If your API uses another body mode, follow the body concatenation rule in Sign your API request.

#

§7 Step 4: Call Get Authorized Shops

After completing the previous steps, press Send to call Get Authorized Shops. If successful, the response should resemble the following: Image Key response fields:

FieldMeaning
data.shops[].cipherEncrypted shop identifier used as shop_cipher in shop-related APIs.
data.shops[].idInternal shop ID.
data.shops[].codeTikTok Shop code displayed in Seller Center.
data.shops[].regionShop region.
data.shops[].seller_typeSeller classification for the shop, such as CROSS_BORDER or LOCAL. This is different from the token response field user_type; see Generate a test access token for token response fields.
#

§8 Troubleshooting

SymptomPossible causeWhat to do
signature is invalidsign was not generated, the body changed after signing, or the timestamp is too old.Regenerate timestamp and sign, then send the request again. Recheck the rule in Sign your API request.
access_token authentication failedThe token is missing, expired, copied incorrectly, or does not match the app.Get a new token or refresh the token. See Generate a test access token.
Download link failsSome clients do not handle raw [[ in the CDN path.Use the encoded ZIP URL in this guide, where [[ is written as %5B%5B.
#