### Install Node.js Dependencies Source: https://partner.tiktokshop.com/docv2/page/integrate-node-js-sdk Use your preferred package manager to install the project dependencies after configuring package.json. ```shell // npm npm install // yarn yarn install // pnpm pnpm i ``` -------------------------------- ### TikTok Shop API Java SDK Example Source: https://partner.tiktokshop.com/docv2/page/integrate-java-sdk This comprehensive example demonstrates the full workflow of using the TikTok Shop Open API Java SDK. It covers obtaining an access token, retrieving shop details, and searching for products. Ensure you have the necessary SDK dependencies and valid credentials. ```java import tiktokshop.open.sdk_java.api.ProductV202502Api; import tiktokshop.open.sdk_java.invoke.ApiClient; import tiktokshop.open.sdk_java.invoke.ApiException; import tiktokshop.open.sdk_java.invoke.Configuration; import tiktokshop.open.sdk_java.model.Product.V202502.SearchProductsRequestBody; import tiktokshop.open.sdk_java.model.Product.V202502.SearchProductsResponse; public class Example { public static void main(String[] args) throws Exception { String appKey = "6fki53g8uldu4"; String appSecret = "7a6028ce703044dd798aa297333ad2b19dfb4e39"; String accessToken = "ROW_yuz9UgAAAAA7n0AT3oGJiYa5j5m45lv_rWWk-KqNdcCNYaB0Q51Whbrh24aCYM1DbbONA6SGPZSky4eFJ1xrIx9UWf_C-HSjb2G3aQv-gyhE6QOG8JgP2ECcDQmTwuHdNQh5QjOF0eY"; String contentType = "application/json"; String shopCipher = "ROW_jKz9TQAAAABBmX6PM8wgVqtjkfVwkwvl"; // 1. get access token AccessTokenAPI accessTokenAPI = new AccessTokenAPI(appKey, appSecret); ResponseInfo getTokenResponse = accessTokenAPI.getToken("ROW_8KPJXgAAAABl9RnFLTHz0mJlo-SXeRCklBr0FykbOOvxCFCMHe4TAAxY0xf5n3tLe-eoN6aCr1WWlLBw1pVAd1CET8ngjFHr4Pj6vMuzIE0bBX7UNFMmZlgH64y7nhuYM-frjWnnHxI"); System.out.println("AccessTokenAPI getToken response: " + getTokenResponse); accessToken = getTokenResponse.getData().getAccessToken(); // refresh token (needed when access token is expired) // ResponseInfo refreshTokenResponse = accessTokenAPI.refreshToken(getTokenResponse.getData().getRefreshToken()); // System.out.println("AccessTokenAPI refreshToken response: " + refreshTokenResponse); // 2. get shop_cipher ApiClient defaultClient = Configuration.getDefaultApiClient() .setAppkey(appKey) .setSecret(appSecret) .setBasePath("https://open-api.tikTokglobalshop.com"); AuthorizationV202309Api authAPIInstance = new AuthorizationV202309Api(defaultClient); try { GetAuthorizedShopsResponse shopsResponse = authAPIInstance.authorization202309ShopsGet(accessToken, contentType); System.out.println(shopsResponse); for (GetAuthorizedShopsResponseDataShops shop : shopsResponse.getData().getShops()) { System.out.println("shop_id: " + shop.getId() + ", shop_cipher: " + shop.getCipher()); } } catch (ApiException e) { System.err.println("Exception when calling AuthorizationV202309Api#authorization202309ShopsGet"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } // 3. search products ProductV202502Api apiInstance = new ProductV202502Api(defaultClient); SearchProductsRequestBody searchProductsRequestBody = new SearchProductsRequestBody(); searchProductsRequestBody.setStatus("ALL"); try { SearchProductsResponse result = apiInstance.product202502ProductsSearchPost(1, accessToken, contentType, null, shopCipher, searchProductsRequestBody); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling ProductV202502Api#product202502ProductsSearchPost"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ``` -------------------------------- ### Call Get Authorized Shops API using cURL Source: https://partner.tiktokshop.com/docv2/page/call-get-authorized-shops Use this cURL command to make a GET request to the Get Authorized Shops API. Ensure you replace placeholders with your actual App key, cryptographic hash, timestamp, and access token. The timestamp must be within five minutes of the timestamp used to create the sign parameter. ```bash curl --location --request GET 'https://open-api.tiktokglobalshop.com/authorization/202309/shops?app_key=&sign=×tamp=' --header 'Content-Type: application/json' --header 'x-tts-access-token: ' ``` -------------------------------- ### Get Access Token using Node.js SDK Source: https://partner.tiktokshop.com/docv2/page/integrate-node-js-sdk Use the AccessTokenTool.getAccessToken method from the SDK to obtain an access token. Ensure you have a valid authorization code. ```javascript const auth_code = "your_auth_code"; const { body } = await AccessTokenTool.getAccessToken(auth_code); console.log('getAccessToken resp data := ', JSON.stringify(body, null, 2)); const access_token = body.data?.access_token; if (!access_token) { throw new Error("Failed to get access token"); } ``` -------------------------------- ### Get Authorized Shops using Java SDK Source: https://partner.tiktokshop.com/docv2/page/integrate-java-sdk This Java code snippet demonstrates how to retrieve a list of authorized shops and their corresponding shop ciphers using the AuthorizationV202309Api. It includes error handling for API exceptions. ```java AuthorizationV202309Api authAPIInstance = new AuthorizationV202309Api(defaultClient); try { GetAuthorizedShopsResponse shopsResponse = authAPIInstance.authorization202309ShopsGet(accessToken, contentType); System.out.println(shopsResponse); for (GetAuthorizedShopsResponseDataShops shop : shopsResponse.getData().getShops()) { System.out.println("shop_id: " + shop.getId() + ", shop_cipher: " + shop.getCipher()); } } catch (ApiException e) { System.err.println("Exception when calling AuthorizationV202309Api#authorization202309ShopsGet"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } ``` -------------------------------- ### Get Shop Cipher using Node.js SDK Source: https://partner.tiktokshop.com/docv2/page/integrate-node-js-sdk Retrieve the shop cipher by calling the ShopsGet API method from the SDK. This is required for product search requests. ```javascript const contentType = 'application/json'; const { body: shopsGetBody } = await client.api.AuthorizationV202309Api.ShopsGet(access_token, contentType); console.log('ShopsGet resp data := ', JSON.stringify(shopsGetBody, null, 2)); const shopList = shopsGetBody.data.shops || []; if (shopList.length === 0) { throw new Error("No authorized shops found."); } shopList.forEach((shop, index) => { const shopId = shop.id; const shopCipher = shop.cipher; console.log(`shop_id: ${shopId}, shop_cipher: ${shopCipher}`); }); ``` -------------------------------- ### GET /authorization/202309/shops Source: https://partner.tiktokshop.com/docv2/page/call-get-authorized-shops Retrieves a list of authorized shops for the authenticated user. This endpoint requires query parameters for authentication and signing, as well as a specific header for the access token. ```APIDOC ## GET /authorization/202309/shops ### Description Retrieves a list of authorized shops associated with the provided credentials. This is typically used after a successful OAuth flow to identify which shops the application has access to. ### Method GET ### Endpoint `/authorization/202309/shops` ### Parameters #### Query Parameters - **app_key** (string) - Required - The App key generated when creating your TikTok Shop App. - **sign** (string) - Required - The cryptographic hash generated to sign the API request. - **timestamp** (Unix timestamp) - Required - The Unix epoch timestamp used to generate the `sign` parameter. Must be within five minutes of the `sign` parameter's creation time. #### Headers - **x-tts-access-token** (string) - Required - The test access token obtained during the authentication process. - **Content-Type** (string) - Required - Set to `application/json`. ### Request Example ```curl curl --location --request GET 'https://open-api.tiktokglobalshop.com/authorization/202309/shops?app_key=&sign=×tamp=' --header 'Content-Type: application/json' --header 'x-tts-access-token: ' ``` ### Response #### Success Response (200) - **code** (integer) - The status code of the response. 0 indicates success. - **data** (object) - Contains the list of shops. - **shops** (array) - A list of shop objects. - **cipher** (string) - The shop cipher. - **code** (string) - The shop code. - **id** (string) - The unique identifier for the shop. - **name** (string) - The name of the shop. - **region** (string) - The region where the shop is located. - **seller_type** (string) - The type of seller. - **message** (string) - A message indicating the status of the response, e.g., "Success". - **request_id** (string) - The unique identifier generated by the TikTok Shop server for the request. #### Response Example ```json { "code": 0, "data": { "shops": [ { "cipher": "", "code": "", "id": "", "name": "", "region": "", "seller_type": "" } ] }, "message": "Success", "request_id": "" } ``` ``` -------------------------------- ### Successful Get Authorized Shops API Response Source: https://partner.tiktokshop.com/docv2/page/call-get-authorized-shops This is the expected JSON response when the Get Authorized Shops API call is successful. It includes shop details such as cipher, code, id, name, region, and seller type. ```json { "code": 0, "data": { "shops": [ { "cipher": "", "code": "", "id": "", "name": "", "region": "", "seller_type": "" } ] }, "message": "Success", "request_id": "" } ``` -------------------------------- ### Initialize and Use TikTok Shop Node.js API Client Source: https://partner.tiktokshop.com/docv2/page/integrate-node-js-sdk This snippet shows how to configure the client with global settings, obtain an access token using an authorization code, retrieve a list of authorized shops, and search for products. Ensure you replace placeholder values with your actual credentials and authorization code. ```javascript import { ClientConfiguration, TikTokShopNodeApiClient,AccessTokenTool } from "."; ClientConfiguration.globalConfig.app_key = "XXXXXXXXX"; ClientConfiguration.globalConfig.app_secret = "XXXXXXXXX"; const access_token = "XXXXXXXXX" const shop_cipher="XXXXXXXXX" const client = new TikTokShopNodeApiClient({ config: { sandbox: false, }, }); const main = async () => { // 1. get access token const auth_code = "your_auth_code"; const { body } = await AccessTokenTool.getAccessToken(auth_code); console.log('getAccessToken resp data := ', JSON.stringify(body, null, 2)); const access_token = body.data?.access_token; if (!access_token) { throw new Error("Failed to get access token"); } // 2. get shop cipher const contentType = 'application/json'; const { body: shopsGetBody } = await client.api.AuthorizationV202309Api.ShopsGet(access_token, contentType); console.log('ShopsGet resp data := ', JSON.stringify(shopsGetBody, null, 2)); const shopList = shopsGetBody.data.shops || []; if (shopList.length === 0) { throw new Error("No authorized shops found."); } shopList.forEach((shop, index) => { const shopId = shop.id; const shopCipher = shop.cipher; console.log(`shop_id: ${shopId}, shop_cipher: ${shopCipher}`); }); // 3. search products const result = await client.api.ProductV202502Api.ProductsSearchPost(1,access_token,'application/json',undefined,undefined, shop_cipher); console.log('resp data := ',JSON.stringify(result.body, null, 2)); }; main(); ``` -------------------------------- ### Configure Node.js Project Dependencies Source: https://partner.tiktokshop.com/docv2/page/integrate-node-js-sdk Add these dependencies to your package.json file to set up your Node.js project for the TikTok Shop SDK. ```json { "dependencies": { "request":"2.88.2" }, "devDependencies": { "@types/request":"2.48.12", "@types/node": "16", "tslib":"2.6.2", "typescript": "^4.9.5", } } ``` ```json { "esModuleInterop": true } ``` -------------------------------- ### Search Products API Request in Java Source: https://partner.tiktokshop.com/docv2/page/integrate-java-sdk Use this Java code to call the ProductV202502Api to search for products. Ensure you have the correct access token, shop cipher, and API client configuration. ```java String accessToken = "ROW_VHM8dXS3r90w3wd67339r84k59v873nd73nf73JF3JKcaY"; // String | String contentType = "application/json"; // String | Allowed type: application/json String shopCipher = "TTP_Pse393kj92728jv9"; ApiClient defaultClient = Configuration.getDefaultApiClient() .setAppkey("wiwiow594") .setSecret("825cahe7h404u04j49dj80wc3d777759c") .setBasePath("https://open-api.tiktokglobalshop.com"); ProductV202502Api apiInstance = new ProductV202502Api(defaultClient); SearchProductsRequestBody searchProductsRequestBody = new SearchProductsRequestBody(); searchProductsRequestBody.setStatus("ALL"); try { SearchProductsResponse result = apiInstance.product202502ProductsSearchPost(1, accessToken, contentType, null, shopCipher, searchProductsRequestBody); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling ProductV202502Api#product202502ProductsSearchPost"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } ``` -------------------------------- ### Search Products using Node.js SDK Source: https://partner.tiktokshop.com/docv2/page/integrate-node-js-sdk Call the ProductsSearchPost API method with the access token and shop cipher to retrieve a list of products. ```javascript const result = await client.api.ProductV202502Api.ProductsSearchPost(1,access_token,'application/json',undefined,undefined, shop_cipher); console.log('resp data := ',JSON.stringify(result.body, null, 2)); ``` -------------------------------- ### Search Products Source: https://partner.tiktokshop.com/docv2/page/integrate-java-sdk Retrieve a list of products that meet specified conditions using Access Token and Shop Cipher. ```APIDOC ## POST /products/search ### Description Retrieves a list of products based on specified criteria. Requires an Access Token and Shop Cipher. ### Method POST ### Endpoint /products/search ### Parameters #### Query Parameters - **access_token** (string) - Required - The access token for authentication. - **shop_cipher** (string) - Required - The shop cipher for identifying the shop. - **page** (integer) - Optional - The page number for pagination. Defaults to 1. - **content_type** (string) - Required - The content type of the request. Allowed: "application/json". #### Request Body - **status** (string) - Optional - The status of the products to search for. Example: "ALL", "ON_SALE", "OFF_SALE", "UNDER_AUDIT". ### Request Example ```json { "status": "ALL" } ``` ### Response #### Success Response (200) - **code** (integer) - The response code. 0 indicates success. - **data** (object) - The data payload containing product information. - **next_page_token** (string) - Token for retrieving the next page of results. - **products** (array) - An array of product objects. - **audit** (object) - Audit information for the product. - **status** (string) - The audit status (e.g., "AUDITING"). - **create_time** (integer) - The creation timestamp of the product. - **id** (string) - The unique identifier of the product. - **integrated_platform_statuses** (array) - Statuses of the product on integrated platforms. - **platform** (string) - The name of the platform. - **status** (string) - The status on the platform (e.g., "PLATFORM_DEACTIVATED"). #### Response Example ```json { "code": 0, "data": { "next_page_token": "b2Zmc2V0PTAK", "products": [ { "audit": { "status": "AUDITING" }, "create_time": 1234567890, "id": "1729592969712207008", "integrated_platform_statuses": [ { "platform": "TOKOPEDIA", "status": "PLATFORM_DEACTIVATED" } ] } ] } } ``` ``` -------------------------------- ### Add Maven Dependency for Java SDK Source: https://partner.tiktokshop.com/docv2/page/integrate-java-sdk Include this dependency in your project's POM file to integrate the Java SDK. Replace '1.0.0' with your downloaded SDK version. ```xml com.tiktokshop open-sdk-java 1.0.0 compile ``` -------------------------------- ### Add Gradle Dependency for Java SDK Source: https://partner.tiktokshop.com/docv2/page/integrate-java-sdk Add this dependency to your build.gradle file to use the Java SDK. Ensure mavenCentral() or mavenLocal() is included in your repositories. Replace '1.0.0' with your downloaded SDK version. ```groovy repositories { mavenCentral() mavenLocal() } dependencies { implementation "com.tiktokshop:open-sdk-java:1.0.0" } ``` -------------------------------- ### Shop Tag Source: https://partner.tiktokshop.com/docv2/page/api-entity-tags Endpoints tagged with 'Shop' operate at the local shop level, requiring a seller access token and a shop cipher for managing data within a specific shop. ```APIDOC ## Shop Tag Endpoints with the `Shop` tag operate at the **local shop level**. A seller access token and a shop cipher is required to access the shop data. Each shop has its own shop cipher, and the data is isolated from other shops. These endpoints are mainly used to manage data within a shop, such as listing a product in a shop, retrieving its orders, and so on. They cannot be used to access or manage data that spans across multiple shops under the same seller account. ``` -------------------------------- ### Successful Search Products API Response in JSON Source: https://partner.tiktokshop.com/docv2/page/integrate-java-sdk This JSON structure represents a successful response from the search products API, including product details and pagination information. ```json { "code": 0, "data": { "next_page_token": "b2Zmc2V0PTAK", "products": [ { "audit": { "status": "AUDITING" }, "create_time": 1234567890, "id": "1729592969712207008", "integrated_platform_statuses": [ { "platform": "TOKOPEDIA", "status": "PLATFORM_DEACTIVATED" } ] } ] } } ``` -------------------------------- ### Asset Tag Source: https://partner.tiktokshop.com/docv2/page/api-entity-tags Endpoints tagged with 'Asset' operate at the partner's campaign asset level, requiring a partner access token and category asset cipher for managing affiliate marketing campaigns and products. ```APIDOC ## Asset Tag Endpoints with the `Asset` tag operate at the **partner's campaign asset level**. A partner access token and the relevant category asset cipher is required to access a partner's campaign data. These endpoints are mainly used to manage affiliate marketing campaigns and handle campaign products. ``` -------------------------------- ### Seller Tag Source: https://partner.tiktokshop.com/docv2/page/api-entity-tags Endpoints tagged with 'Seller' operate at the seller account level, requiring a seller access token for managing seller-wide data and reusable assets. ```APIDOC ## Seller Tag Endpoints with the `Seller` tag operate at the **seller account level**. A seller access token is required to access the seller's data. These endpoints are mainly used to manage seller-level data that support cross-shop operations. This includes seller-wide metadata (e.g. retrieving shops owned by the seller), reusable assets (e.g. uploading shop-agnostic images), and global product data used to replicate local product listings across multiple shops (e.g. creating global product). They cannot be used to access or manage individual local shop data such as local products or a shop's orders. ``` -------------------------------- ### Account Tag Source: https://partner.tiktokshop.com/docv2/page/api-entity-tags Endpoints tagged with 'Account' operate at the partner account level, requiring a partner access token for managing partner-related data like authorized business category assets. ```APIDOC ## Account Tag Endpoints with the `Account` tag operate at the **partner account level.** A partner access token is required to access the partner's data. These endpoints are mainly used for managing data related to the partner account, such as retrieving the list of business category assets that a partner has authorized for an app. They cannot be used to access or manage a partner's campaign assets directly. ``` -------------------------------- ### Creator Tag Source: https://partner.tiktokshop.com/docv2/page/api-entity-tags Endpoints tagged with 'Creator' operate at the creator account level, requiring a creator access token for managing creator-specific data such as profile information and affiliate orders. ```APIDOC ## Creator Tag Endpoints with the `Creator` tag operate at the **creator account level.** A creator access token is required to access the creator's data. These endpoints are mainly used to manage data related to a creator, such as obtaining a creator's profile, retrieving affiliate orders generated by the creator, searching for open collaboration items, and so on. ``` -------------------------------- ### API Entity Tag Overview Source: https://partner.tiktokshop.com/docv2/page/api-entity-tags Entity tags in the TikTok Shop API Reference group endpoints by the type of entity they operate on, clarifying access boundaries and authorization requirements. ```APIDOC ## API Entity Tags In the TikTok Shop API Reference, each endpoint is grouped under one **entity tag**. These tags enable developers to quickly understand: * The type of entity the API operates on (e.g., seller, shop, partner, creator, asset) and its access boundaries * The type of authorization required (e.g., shop token, seller token) This organization provides developers with clear context about each endpoint's scope, and use it correctly within their integration. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.