Guides
Getting started

Authentication

Advertiser authorization, exchanging the auth_code for a token that never expires, the Access-Token header, numeric scopes and revocation.

The Marketing API authenticates with a long-term token issued to your developer app after the advertiser authorizes access to their ad accounts. The flow has three steps: the authorization page, the auth_code exchange, and the token in the Access-Token header.

1. Send the advertiser to the authorization page

text
https://tiktok-ads.mimicr.dev/portal/auth?app_id=<app_id>&state=<your_state>&redirect_uri=https://app.example.com/tiktok/callback

That is the format of the "Advertiser authorization URL" TikTok's My Apps generates. The legacy format, /marketing_api/auth?app_id=…&state=…&scope=…&redirect_uri=…, works too; the URL's scope is ignored, because scopes come from the app configuration.

The page shows the app name and its permissions, a TikTok for Business user of the sandbox to act as, the ad accounts that user can grant and the Platform Service Agreement. In Mimicr TikTok's e-mail verification step is skipped.

  • Confirm redirects to redirect_uri?auth_code=<code>&code=<code>&state=<state>. In Mimicr code and auth_code carry the same value, so integrations that read either one work.
  • Cancel redirects to redirect_uri?state=<state>&error=access_denied&error_description=The+user+denied+the+authorization. TikTok does not document this return; it is Mimicr's decision.
  • Choosing the user with no accounts ("Bruno Sem Contas") is allowed: the token comes with advertiser_ids: [].

An unknown app_id shows the "App not found" error page. A redirect_uri outside the app's URLs shows "redirect_uri mismatch", but only when the anyRedirectUri toggle is off; when it is on (the default), any http(s) URL is accepted. Register the URLs with PUT /v1/tiktok-ads/app (up to 10, see Sandbox control).

2. Exchange the auth_code

The auth_code is valid for 1 hour and can be used once.

bash
curl --request POST \
  --url https://tiktok-ads.mimicr.dev/open_api/v1.3/oauth2/access_token/ \
  --header 'Content-Type: application/json' \
  --data '{ "app_id": "<app_id>", "secret": "<secret>", "auth_code": "<auth_code>" }'
json
{
  "code": 0,
  "message": "OK",
  "request_id": "20261106124316DE1EDD1A109659693A",
  "data": {
    "access_token": "<token>",
    "scope": [1, 2, 3, 4, 5, 6, 8, 12000000],
    "advertiser_ids": ["7000000013373458730", "7000000013373458735", "7000000013373458740"]
  }
}

There is no expires_in, refresh_token or token_type: the token never expires. With "return_advertiser_ids": false, the list comes back empty. This route only accepts application/json.

The same exchange exists in OAuth format at /oauth/token/: client_id, client_secret, code and grant_type=authorization_code, as JSON or form, with a flat response (no data).

Casecodemessage
Missing field40002Missing required field(s): auth_code.
Unknown app_id40113The app has been blocked or does not exist.
Wrong secret40101Invalid parameter values for authentication.
Unknown auth_code, or one of another app40101Invalid auth_code. Not able to get long-term access_token with an old auth_code.
auth_code already used or expired40110The auth_code is canceled. Please re-authorize and try again with a new auth_code.
Another grant_type on /oauth/token/40108Invalid value for grant_type: … is not supported.

3. Use the token

Every Marketing API call carries the token in the Access-Token header, not in Authorization: Bearer:

bash
curl --url https://tiktok-ads.mimicr.dev/open_api/v1.3/user/info/ \
  --header 'Access-Token: <token>'
Casecode
No header40104 The access_token is empty.
Unknown or revoked token40105 Access token is incorrect or has been revoked.
advertiser_id not granted to the token40001 No permission to operate advertiser <id>.
advertiser_id does not exist40300 The advertiser does not exist or has been deleted.
Token without the route's scope40001 No permission to perform the related operation.
A write on a STATUS_DISABLE advertiser40001 Advertiser <id> is disabled.

All of them come with HTTP 200. Code 40102 (expired token) never appears, because Marketing API tokens do not expire.

Scopes

The token carries numeric permission ids, not names:

idPermissionRoutes in Mimicr
1Ad Account Management/advertiser/info/, /oauth2/advertiser/get/, /bc/get/
2Ads Managementcampaigns, ad groups and ads
3Audience Managementnone in the core
4Reporting/report/*
5Measurement/event/track/
6Creative Management/file/*, /identity/*
8Pixel Management/pixel/list/
12000000Lead Management/page/get/, /page/lead/*, /lead/*

/user/info/, /subscription/* and the token routes need no scope. The sandbox app starts with all of them; change them with PUT /v1/tiktok-ads/app {"scopes": [1, 2, 4]}. The change applies to the next authorizations.

No refresh

Marketing API tokens have no refresh token. A call to /oauth2/refresh_token/ answers 40107 Invalid or incorrect refresh token., the documented error for trying to refresh a long-term token. Keep the token and ask for a new authorization only when it is revoked (40105).

Revoke

bash
curl --request POST \
  --url https://tiktok-ads.mimicr.dev/open_api/v1.3/oauth2/revoke_token/ \
  --header 'Access-Token: <token>' \
  --header 'Content-Type: application/json' \
  --data '{ "app_id": "<app_id>", "secret": "<secret>", "access_token": "<token>" }'

The Access-Token header is required (without it: 40104 and nothing is revoked). The response lists the accounts the token can no longer reach, and the webhook subscriptions created with the token stop firing.

Mimicr shortcuts

  • POST https://api.mimicr.dev/v1/tiktok-ads/token authorizes and exchanges the code in one go, with optional user_id and advertiser_ids.
  • The oauth.authorize action plays the Confirm button and returns the auth_code and the redirect, for tests without a browser.
  • The oauth.revoke and oauth.deauthorize_advertiser actions simulate the advertiser revoking access (40105) or removing an account (40001).

See Sandbox control.