# Tiktok Marketing API Export Integration TikTok is a global social networking service that focuses on short-form videos and reports having 1 billion active monthly users around the globe. You can use TikTok's Marketing API to target customers by creating custom segments. Treasure Data's [TikTok](https://ads.tiktok.com/marketing_api/homepage) Integration allows you to send job results from Treasure Data directly to TikTok Marketing using custom audiences. ## What can you do with this Integration? - Send audience segments to TikTok to build the best-fit campaign to retarget existing customers and attract more look-alike audiences. - Stop targeting when end-users explicitly give opt-out consent. ## Prerequisites - Basic Knowledge of Treasure Data. - Basic knowledge of [TikTok Ads Manager and TikTok Marketing API](https://ads.tiktok.com/marketing_api/docs?id=1701890905779201). - If you select token-based authentication method (Not required for the Oauth Method): - A [developer account](https://ads.tiktok.com/marketing_api/docs?id=1701890911024129) and an approved application in [TikTok Marketing API](https://ads.tiktok.com/marketing_api/homepage). - Obtain an access token from TikTok using your preferred tool for making API requests. ## Requirements and Limitations - The maximum file size to be uploaded is 50MB per file and 500 files per audience, which means we only support uploading a maximum of 50MB * 500 files = 25000 MB ~ 25GB. Due to the plugin's restriction, the actual size is around 20GB. - After creating an audience, the audience will be accessible within one hour. - There is a maximum of 400 custom audiences. - Data before hashing needs to be in all uppercase or lowercase. - A minimum audience size of 1,000 is required to target custom audiences in an ad group. - The audience size will update within **24-48 hours** on the Audiences page in TikTok's Ads Manager. - If you use **OAuth authentication** method, because of API Quotas on Tiktok OAuth Application, you might get the Quota warnings. Some delay would be expected while the connector will automatically retry after a certain duration to continue the job. - If you use **token-based authentication** method, please contact your TikTok representative to whitelisting certain API access (such as Streaming API). ## Use the TD Console to Create Your Connection ### Create a New Connection In Treasure Data, you must create and configure the data connection prior to running your query. As part of the data connection, you provide authentication to access the integration. 1. Open **TD Console**. 2. Navigate to **Integrations Hub** > **Catalog**. 3. Search for and select TikTok. ![](/assets/72058435.63bec4373dea4cd0dd6afbda613b3ddf95503b4d8d6531cd08cf56eab184175d.1ee14251.png) 1. Select **Create Authentication**. 2. Select **Authentication Mode** Recommendation: Use the OAuth Flow We strongly recommend using the OAuth flow for the following reasons: 1. Simplicity and Convenience: The OAuth flow is designed to be user-friendly, allowing you to authorize your TikTok Ads account quickly and easily without the need to manage developer credentials. 2. Security: OAuth is a secure industry standard for authorization. It ensures that your credentials are protected, reducing the risk of exposing sensitive information. 3. Maintenance-Free: By using OAuth, you avoid the need for ongoing maintenance and updates that come with managing your own developer app. TreasureData will handle all the complexities, letting you focus on your marketing campaigns. 4. Time-Saving and Less Error-Prone: Creating a developer account and then developing an app to obtain an access token is a time-consuming process. It involves multiple steps, including setting up the app, managing keys, and ensuring compliance with TikTok's policies, which can be error-prone and tedious. **Select Oauth as Authentication Mode** - Log into your TikTok account in the browser (if you haven’t logged in previously) and grant permissions to **Treasure Data - TikTok Data Connector** by select **Confirm** ![](/assets/83511415.feac7ceb07b448482adb3a602148907fe9dcacea3d7d66bfea35b80f4bb70761.1ee14251.png) - After Confirmation, you're redirected back Catalog page. Select Tiktok, and you can select **Continue** with your newly created Oauth connection. **Select Access Token - Authentication Mode** - Type the access token to authenticate and select **Continue**. - To create a Tiktok Access Token, please refer to this guide [HERE](/int/guides-for-creating-tiktok-marketing-api-developer-account-and-application). ![](/assets/72058434.6ce9159a70716fd1d8b603a8525451ebc84cc2e31c9a56b4b2b295cf86993146.1ee14251.png) 1. Type a name for your New connection. 2. Select **Done**. ### Define your Query Your query requires the id column. 1. Complete the instructions for [creating a destination integration](https://docs.treasuredata.com/smart/project-product-documentation/creating-a-destination-integration). 2. Navigate to **Data Workbench > Queries**. 3. Select a query for which you would like to export data. 4. Run the query to validate the result set. 5. Select **Export Results**. 6. Select an existing integration authentication. ![](/assets/72058432.09e8af43184e33e337bef7c546600eaaa5be9f010b690af1d591c7c2b4bb2df3.1ee14251.png) 7. Define any additional Export Results details. In your export integration content, review the integration parameters. For example, your Export Results screen might be different, or you might not have additional details to complete. ![](/assets/72058430.dbfc46347631c97a7b8a5007fe3124805c3b8bec4a47ef692b0b3cf31991f1ca.1ee14251.png) 1. Select **Done**. 2. Run your query. 3. Validate that your data moved to the destination you specified. ### Integration Parameters for TikTok | Parameter | Types | Description | | --- | --- | --- | | auth_method | Enum:- oauth - access_token | This connector support two Authentication methods: - **OAuth** authentication - User can input access_token directly in UI - Required to create your own Tiktok App. Please refer [HERE](https://docs.treasuredata.com/display/INT/TikTok+Marketing+API+Export+Integration#TikTokMarketingAPIExportIntegration-CreatingYourOwnTikTokMarketingAPIDeveloperAccountandApplication). | | access_token | String | For Access Token mode only. | | use_sandbox | boolean | For Access Token mode only. Flag to indicate that you are trying to push the segment to the sandbox environment of TikTok. | | api_mode | Enum, supported values: - CUSTOMER_FILE - STREAMING | Supported TikTok API mode.- **Recommendation: Use the Streaming API** We strongly recommend using the Streaming API for the following reasons: 1. **Real-Time Data Updates**: The Streaming API allows for real-time data updates, ensuring your customer data is always current. This is crucial for activating audiences and launching campaigns with the most up-to-date information. 2. **Better Throughput for High Volume Data**: If you handle large volumes of data, the Streaming API offers better throughput, making it more efficient and reliable for high-volume data synchronization. 3. **Future-Proofing**: TikTok plans to deprecate the Customer File API. By choosing the Streaming API now, you avoid the need for future migrations, saving you time and effort down the line. | | advertiser_id | String | Your advertiser's id on TikTok. | | audience_name | String | Audience's name. **Note:** This configuration key is used for CUSTOMER_FILE mode only. | | encryption_type | Enum (FIRST_SHA256, FIRST_MD5, EMAIL_SHA256, PHONE_SHA256, IDFA_SHA256, IDFA_MD5, GAID_SHA256, GAID_MD5) | ID Type. **Note:** This configuration key is used for CUSTOMER_FILE mode only. | | audience_action | Enum- APPEND - REMOVE, - REPLACE | Audience's Action (REMOVE, REPLACE, ADD). **Note:** This configuration key is used for CUSTOMER_FILE mode only. | | streaming_action | Enum, supported values:- ADD - DELETE - DELETE_AUDIENCE | Streaming export mode and the default value is ADD. **Note:** This configuration key is used for STREAMING mode only. | | audience_names | String | List of segment audience names separated by comma. **Note:** This configuration key is used for STREAMING mode only. | | audience_ids | String | List of audience IDs separated by comma. **Note:** This configuration key is used for STREAMING mode only. | | skip_invalid_record | boolean | - true: Skip the invalid record and continue the job - false: Stop job when processing invalid record | | thread_count | Integer | Configurable parallel request to TikTok. The default value is 5. **Note:** This configuration key is used for STREAMING mode only. | ### Example Query The CUSTOMER_FILE mode, it supports only one column/alias with name **id** ```sql SELECT id FROM my_table ``` The Streaming mode can support multiple columns/alias: **email, email_sha256, phone, phone_sha256, idfa, idfa_md5, idfa_sha256, aaid, aaid_md5, aaid_sha256** ```sql SELECT email, phone, idfa, aaid FROM my_table ``` ### (Optional) Schedule Query Export Jobs You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify. Treasure Data's scheduler feature supports periodic query execution to achieve high availability. When two specifications provide conflicting schedule specifications, the specification requesting to execute more often is followed while the other schedule specification is ignored. For example, if the cron schedule is `'0 0 1 * 1'`, then the 'day of month' specification and 'day of week' are discordant because the former specification requires it to run every first day of each month at midnight (00:00), while the latter specification requires it to run every Monday at midnight (00:00). The latter specification is followed. #### Scheduling your Job Using TD Console 1. Navigate to **Data Workbench > Queries** 2. Create a new query or select an existing query. 3. Next to **Schedule**, select None. ![](/assets/image2021-1-15_17-28-51.f1b242f6ecc7666a0097fdf37edd1682786ec11ef80eff68c66f091bc405c371.0f87d8d4.png) 4. In the drop-down, select one of the following schedule options: ![](/assets/image2021-1-15_17-29-47.45289a1c99256f125f4d887e501e204ed61f02223fde0927af5f425a89ace0c0.0f87d8d4.png) | Drop-down Value | Description | | --- | --- | | Custom cron... | Review [Custom cron... details](#custom-cron-details). | | @daily (midnight) | Run once a day at midnight (00:00 am) in the specified time zone. | | @hourly (:00) | Run every hour at 00 minutes. | | None | No schedule. | #### Custom cron... Details ![](/assets/image2021-1-15_17-30-23.0f94a8aa5f75ea03e3fec0c25b0640cd59ee48d1804a83701e5f2372deae466c.0f87d8d4.png) | **Cron Value** | **Description** | | --- | --- | | `0 * * * *` | Run once an hour. | | `0 0 * * *` | Run once a day at midnight. | | `0 0 1 * *` | Run once a month at midnight on the morning of the first day of the month. | | "" | Create a job that has no scheduled run time. | ``` * * * * * - - - - - | | | | | | | | | +----- day of week (0 - 6) (Sunday=0) | | | +---------- month (1 - 12) | | +--------------- day of month (1 - 31) | +-------------------- hour (0 - 23) +------------------------- min (0 - 59) ``` The following named entries can be used: - Day of Week: sun, mon, tue, wed, thu, fri, sat. - Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec. A single space is required between each field. The values for each field can be composed of: | Field Value | Example | Example Description | | --- | --- | --- | | A single value, within the limits displayed above for each field. | | | | A wildcard `'*'` to indicate no restriction based on the field. | `'0 0 1 * *'` | Configures the schedule to run at midnight (00:00) on the first day of each month. | | A range `'2-5'`, indicating the range of accepted values for the field. | `'0 0 1-10 * *'` | Configures the schedule to run at midnight (00:00) on the first 10 days of each month. | | A list of comma-separated values `'2,3,4,5'`, indicating the list of accepted values for the field. | `0 0 1,11,21 * *'` | Configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month. | | A periodicity indicator `'*/5'` to express how often based on the field's valid range of values a schedule is allowed to run. | `'30 */2 1 * *'` | Configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. `'0 0 */5 * *'` configures the schedule to run at midnight (00:00) every 5 days starting on the 5th of each month. | | A comma-separated list of any of the above except the `'*'` wildcard is also supported `'2,*/5,8-10'`. | `'0 0 5,*/10,25 * *'` | Configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month. | 1. (Optional) You can delay the start time of a query by enabling the Delay execution. ### Execute the Query Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically exported to the specified destination. Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications. (Optional) You can delay the start time of a query by enabling the Delay execution. ## Activate a Segment in Audience Studio You can also send segment data to the target platform by creating an activation in the Audience Studio. 1. Navigate to **Audience Studio**. 2. Select a parent segment. 3. Open the target segment, right-mouse click, and then select **Create Activation.** 4. In the **Details** panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters. 5. Customize the activation output in the **Output Mapping** panel. ![](/assets/ouput.b2c7f1d909c4f98ed10f5300df858a4b19f71a3b0834df952f5fb24018a5ea78.8ebdf569.png) - Attribute Columns - Select **Export All Columns** to export all columns without making any changes. - Select **+ Add Columns** to add specific columns for the export. The Output Column Name pre-populates with the same Source column name. You can update the Output Column Name. Continue to select **+ Add Columns**to add new columns for your activation output. - String Builder - **+ Add string** to create strings for export. Select from the following values: - String: Choose any value; use text to create a custom value. - Timestamp: The date and time of the export. - Segment Id: The segment ID number. - Segment Name: The segment name. - Audience Id: The parent segment number. 1. Set a **Schedule**. ![](/assets/snippet-output-connector-on-audience-studio-2024-08-28.a99525173709da1eb537f839019fa7876ffae95045154c8f2941b030022f792c.8ebdf569.png) - Select the values to define your schedule and optionally include email notifications. 1. Select **Create**. If you need to create an activation for a batch journey, review [Creating a Batch Journey Activation](/products/customer-data-platform/journey-orchestration/batch/creating-a-batch-journey-activation). ## Example TD CLI ```bash td query \ -d my_database \ -r '{ "accessToken": "__SAVED__", "useSandbox": true, "advertiserId": "12345678901234567890", "apiVersion": "v1.2", "audienceAction": "REPLACE", "audienceName": "test", "encryptionType": "FIRST_NORMAL" }' \ "SELECT id FROM my_table" \ -T presto ```