Guides
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
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 Mimicrcodeandauth_codecarry 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.
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>" }'{
"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).
| Case | code | message |
|---|---|---|
| Missing field | 40002 | Missing required field(s): auth_code. |
Unknown app_id | 40113 | The app has been blocked or does not exist. |
Wrong secret | 40101 | Invalid parameter values for authentication. |
Unknown auth_code, or one of another app | 40101 | Invalid auth_code. Not able to get long-term access_token with an old auth_code. |
auth_code already used or expired | 40110 | The auth_code is canceled. Please re-authorize and try again with a new auth_code. |
Another grant_type on /oauth/token/ | 40108 | Invalid 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:
curl --url https://tiktok-ads.mimicr.dev/open_api/v1.3/user/info/ \ --header 'Access-Token: <token>'
| Case | code |
|---|---|
| No header | 40104 The access_token is empty. |
| Unknown or revoked token | 40105 Access token is incorrect or has been revoked. |
advertiser_id not granted to the token | 40001 No permission to operate advertiser <id>. |
advertiser_id does not exist | 40300 The advertiser does not exist or has been deleted. |
| Token without the route's scope | 40001 No permission to perform the related operation. |
A write on a STATUS_DISABLE advertiser | 40001 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:
| id | Permission | Routes in Mimicr |
|---|---|---|
| 1 | Ad Account Management | /advertiser/info/, /oauth2/advertiser/get/, /bc/get/ |
| 2 | Ads Management | campaigns, ad groups and ads |
| 3 | Audience Management | none in the core |
| 4 | Reporting | /report/* |
| 5 | Measurement | /event/track/ |
| 6 | Creative Management | /file/*, /identity/* |
| 8 | Pixel Management | /pixel/list/ |
| 12000000 | Lead 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
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/tokenauthorizes and exchanges the code in one go, with optionaluser_idandadvertiser_ids.- The
oauth.authorizeaction plays the Confirm button and returns theauth_codeand the redirect, for tests without a browser. - The
oauth.revokeandoauth.deauthorize_advertiseractions simulate the advertiser revoking access (40105) or removing an account (40001).
See Sandbox control.