Upload a file
Use this endpoint to upload a file. The transfer speed is limited by your network bandwidth. The maximum size of a file that you can upload is 100 MB.
After you upload a file to TikTok’s file repository, a file_id will be returned in the response. You can use the file_id to retrieve the file in the repository and transfer it to the Asset Library.
> Note
> Once a file is uploaded to the file repository, it is kept for 24 hours, after which it will expire. If the file you want to use in your ads expires, you need to re-upload the file to the file repository.
Request
Endpoint
Authentication & shop
| Name | In | Type | Sample | Description |
|---|---|---|---|---|
| Authorization | header | header | Bearer q360_live_ab12cd34_… | Khóa API của brand (tạo ở mục API key). Bắt buộc với mọi request. Brand suy từ key — không truyền mã brand. |
| platform_shop_id | query | string | 7000000000000000001 | Tài sản TikTok Business đã kết nối — "Mã tài sản" ở trang Nền tảng hoặc GET /v1/platforms (tài khoản quảng cáo cho Marketing API, tài khoản TikTok cho Organic / Messaging). Có thể bỏ khi chỉ kết nối một tài sản. |
Request parameters
| Name | In | Type | Required | Sample | Description |
|---|---|---|---|---|---|
| upload_type | body | string | Yes | The upload type.
Enum values:FILE, URL | |
| content_type | body | string | Yes | The file type.
Enum values:image, music, video, playable | |
| file | body | file | No | The file that you want to upload. Required when upload_typeis set toFILE. The maximum size of a file that you can upload is 100 MB.
Note: To upload a customized music file that can be used in Carousel Ads, the file that you specify through this field should meet the following specifications requirements:
- File Type: MP3.
- File Size: no greater than 10 MB. | |
| url | body | string | No | The URL of the file that you want to upload, in the format of “ Required when upload_type is URL. | |
| signature | body | string | No | The MD5 value of the file, used as a checksum to check data integrity by the server side. Required when upload_type is FILE. | |
| name | body | string | No | The file name. Character limit is 100. Note: Each word in Chinese or Japanese counts as three characters, while each letter in English counts as one character. |
Request examples
curl -s -X POST "https://partner.quantri360.com/v1/tiktok_business/file/temporarily/upload/" \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{"upload_type":"","content_type":""}'
Python
import requests
KEY = "q360_live_..." # khóa API của brand
r = requests.post(
"https://partner.quantri360.com/v1/tiktok_business/file/temporarily/upload/",
params={},
json={
"upload_type": "",
"content_type": ""
},
headers={"Authorization": f"Bearer {KEY}"},
timeout=60,
)
print(r.status_code)
print(r.json())Node.js
const KEY = 'q360_live_...'; // khóa API của brand
const url = new URL('https://partner.quantri360.com/v1/tiktok_business/file/temporarily/upload/');
for (const [k, v] of Object.entries({})) url.searchParams.set(k, typeof v === 'object' ? JSON.stringify(v) : String(v));
const r = await fetch(url, {
method: 'POST',
headers: { Authorization: `Bearer ${KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({"upload_type":"","content_type":""}),
});
console.log(r.status, await r.json());PHP
<?php
$key = 'q360_live_...'; // khóa API của brand
$url = 'https://partner.quantri360.com/v1/tiktok_business/file/temporarily/upload/' . '?' . http_build_query([]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $key, 'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"upload_type":"","content_type":""}');
$res = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $status, "\n", $res;Response
Response fields (as returned by TikTok Business)
| Name | Type | Sample | Description |
|---|---|---|---|
| code | number | The response code. For the complete list of response codes and descriptions, see Appendix - Return Codes. | |
| message | string | The response message. For details, see Appendix - Return Codes. | |
| data | object | The returned data. | |
| file_id | string | The ID of the file that you have uploaded. You can use this ID to upload the file from the file library to the creatives library. It is valid for 24 hours. | |
| signature | string | The MD5 value of the file. | |
| file_size | number | The file size in bytes. | |
| create_time | string | The time when the file was uploaded in the format of YYYY-MM-DD HH:MM:SS(UTC+0). Example: 2020-06-10 07:39:14. | |
| request_id | string | The unique ID of the request. |
Response sample
HTTPS/1.1 200 OK
{
"message": "OK",
"code": 0,
"data": {
"file_id": "264c544d8d383388383c8a8129b33a74_1609142644",
"signature": "264c544d8d383388383c8a8129b33a74",
"create_time": "2020-12-28 08:04:04",
"file_size": 1645516
},
"request_id": "202012280804020101151761271A085384"
}
(/code);
Get started
- Sign up for Partner
- Enable a data type of the Ads (Marketing API) group on the platform page
- Create an API key (tick the TikTok Business channel)
- Call it as in the examples above