Skip to content

Calling the API

Create the Go TikTokShop client, call operations by API area, and work with many shops using WithShop.

tiktokshop.New returns the API client, a *TikTokShop. It never fails and does no I/O. 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 (
"context"
"fmt"
tiktokshop "github.com/isaackogan/TikTok-Shop-Api-SDKs/go"
)
func listOrders(ctx context.Context) error {
client := tiktokshop.New(tiktokshop.Options{
AppKey: "APP_KEY",
AppSecret: "APP_SECRET",
AccessToken: "ACCESS_TOKEN",
ShopCipher: "SHOP_CIPHER",
})
orders, _, err := client.Orders.GetOrderList(ctx).PageSize(20).Execute()
if err != nil {
return err
}
data := orders.GetData()
fmt.Println(data.GetTotalCount(), "orders; request", orders.GetRequestId())
return nil
}

One field per API area hangs off the client, matching the spec’s tags. Each holds the generated service for that area:

FieldArea
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 operation is a method that takes a context.Context and returns a request builder. Set parameters on the builder, such as PageSize(20), then call Execute() to send the request. It returns the typed response, the *http.Response and an error. Names follow the API reference, in Pascal case.

An operation whose optional request body you leave unset sends no body at all.

WithShop returns a client for another shop that shares the HTTP transport, base URL and timeout. A value you leave out keeps this client’s value; passing it empty clears it. The original is never changed.

import (
tiktokshop "github.com/isaackogan/TikTok-Shop-Api-SDKs/go"
)
func otherShop(client *tiktokshop.TikTokShop) *tiktokshop.TikTokShop {
return client.WithShop(
tiktokshop.ShopAccessToken("OTHER_ACCESS_TOKEN"),
tiktokshop.ShopCipher("OTHER_SHOP_CIPHER"),
)
}
OptionMeaning
AppKey, AppSecretYour app’s credentials.
AccessTokenThe seller’s access token, sent in x-tts-access-token. Empty sends none.
ShopCipherThe shop cipher added to operations that need one. Empty adds none.
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 DefaultBaseURL, https://open-api.tiktokglobalshop.com.
TimeoutBounds one request, response body included. 0 means DefaultTimeout (30 seconds); a negative value means no limit.
TransportAn http.RoundTripper carrying the signed requests. nil means http.DefaultTransport, which honours the proxy environment variables (HTTP_PROXY, HTTPS_PROXY).

The client the SDK builds around the transport never follows a redirect. A 3xx reply is returned as a *tiktokshop.Error carrying the status, so the access token is never forwarded to another host. A Transport you supply is used as it is.

Query values are signed decoded, exactly as the server receives them. A request body is sent as is on any method, GET included.

Requests carry the User-Agent tiktok-shop-api-go/<version>. Options.String describes the options without the app secret, the access token or the shop cipher.