Published on

TikTok Ads API Tutorial: Fetching campaigns data

Introduction

In this tutorial, we will explore how to interact with the TikTok Ads API to fetch campaign data using the access token we created in a previous video. We will detail the necessary steps and parameters involved in making an API request.

Setting Up the API Call

To begin, we need to ensure that we have the access token from our previous authentication step. This token will be used as a header argument in our API requests to authenticate our calls to TikTok's servers.

Let's start by launching Insomnia, a popular API client, where we can make our requests. In our previous request, we obtained our access token by providing the authentication code, secret, and app ID. Now, we will copy that access token to use it in our upcoming API request.

Preparing the Request

Every API call to TikTok requires us to pass the access token as a header argument. The header structure should look like this:

Authorization: Bearer (access_token)
Content-Type: application/json

Now that the header is set up, we will consult the TikTok Ads API documentation, specifically the campaign management section, to understand what requests we can make.

Understanding Campaign Structure

TikTok's campaign structure follows a familiar three-tiered hierarchy:

  1. Campaign: This level includes attributes such as the objective and budget.
  2. Ad Group: Sometimes referred to as an ad set on other platforms, this level allows for additional budget settings, promoted objects, placements, targeting audiences, and bidding strategies.
  3. Ad: At this level, you define the creative aspects of your advertisement, including formats, videos, images, text, and calls to action.

With this structure in mind, we can move on to making our API request to fetch campaigns.

Making the API Request

We will start by calling the endpoint that retrieves all campaigns associated with an advertiser account. The API endpoint we're interested in looks something like this: GET https://business-api.tiktok.com/open_api/v1.3/campaign/get/.

However, to make a successful request, certain parameters are required, the most important of which is the advertiser ID (also known as account ID). You can find your advertiser ID in the TikTok Ads Manager. It appears in the URL as the aadv parameter.

To prepare our request, we will include the advertiser ID as a URL parameter:

?advertiser_id=(your_advertiser_id)

Sending the Request

In Insomnia, we will create a new request, set the method to GET, and attach our headers, including the access token we obtained earlier. Here's how it looks:

  1. URL: https://business-api.tiktok.com/open_api/v1.3/campaign/get/?advertiser_id=(your_advertiser_id)
  2. Headers:
    • Authorization: Bearer (access_token)
    • Content-Type: application/json

When sending this request, you should get a response indicating whether the operation was successful.

Handling the Response

If the request is successful, you will receive a response containing a code and a message, alongside the actual campaign data under the data field. The page_info object will tell you if the response is paginated, revealing how many total campaigns exist and providing the current page's data.

When working with large datasets, you can specify the page_size parameter to control how many items you retrieve in one call, up to a maximum of 1000. For example:

?page_size=1000

This will allow you to retrieve all available campaigns in fewer API calls.

Keywords

  • TikTok
  • Ads API
  • Access Token
  • Campaign
  • Ad Group
  • Advertiser ID
  • API Request
  • JSON
  • Pagination
  • Page Size

FAQ

1. What is the TikTok Ads API?
The TikTok Ads API allows developers to programmatically access and manage advertising campaigns on TikTok, helping with automation and analytics.

2. How do I obtain an access token for the API?
You can obtain an access token by authenticating your app with your credentials (app ID and secret) and the authorization code.

3. What are the key components of a TikTok ad campaign?
A TikTok ad campaign consists of three main components: Campaign, Ad Group, and Ad, each with its own attributes like objectives, budgets, placements, and creatives.

4. How do I make a request to fetch campaigns?
You can make a GET request to the campaign endpoint, including your access token in the header and the advertiser ID as a URL parameter.

5. What should I do if the response is paginated?
If the response is paginated, you can specify a page_size to control how many campaigns you retrieve in each request, and use the page parameter to navigate through the data.