productivity
TikTok Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the TikTok KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.tiktok.*.
Use lua_read_doc("integrations.tiktok") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
TikTok workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.tiktok.list_videos({advertiser_id = "example_advertiser_id", page = 1, page_size = 1}))' --json kosmo integrations:lua --eval 'print(docs.read("tiktok"))' --json
kosmo integrations:lua --eval 'print(docs.read("tiktok.list_videos"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local tiktok = app.integrations.tiktok
local result = tiktok.list_videos({advertiser_id = "example_advertiser_id", page = 1, page_size = 1})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.tiktok, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.tiktok.default.* or app.integrations.tiktok.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need TikTok, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
TikTok — Lua API Reference
list_videos
List videos available for an advertiser in TikTok Business.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
page | integer | no | Page number for pagination. Defaults to 1. |
page_size | integer | no | Number of videos per page. Defaults to 10. |
Example
local result = app.integrations.tiktok.list_videos({
advertiser_id = "123456789",
page_size = 20
})
for _, video in ipairs(result.data.list) do
print(video.video_name .. " (ID: " .. video.video_id .. ")")
end
get_video
Get details for a specific TikTok video, including preview URL, duration, and status.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
video_id | string | yes | The TikTok video ID. |
Example
local result = app.integrations.tiktok.get_video({
advertiser_id = "123456789",
video_id = "v001"
})
print(result.data.video_name)
print("Duration: " .. result.data.duration .. "s")
print("Preview: " .. result.data.preview_url)
upload_video
Upload a video to TikTok via URL for use in advertising campaigns.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
video_url | string | yes | URL of the video to upload (must be publicly accessible). |
file_name | string | no | Custom name for the uploaded video file. |
Example
local result = app.integrations.tiktok.upload_video({
advertiser_id = "123456789",
video_url = "https://example.com/videos/ad-creative.mp4",
file_name = "summer-campaign-creative"
})
print("Uploaded video ID: " .. result.video_id)
list_campaigns
List advertising campaigns for a TikTok advertiser.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
page | integer | no | Page number for pagination. Defaults to 1. |
page_size | integer | no | Number of campaigns per page. Defaults to 10. |
Example
local result = app.integrations.tiktok.list_campaigns({
advertiser_id = "123456789",
page_size = 20
})
for _, campaign in ipairs(result.data.list) do
print(campaign.campaign_name .. " — Status: " .. campaign.status)
end
get_campaign
Get details for a specific TikTok advertising campaign.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
campaign_id | string | yes | The TikTok campaign ID. |
Example
local result = app.integrations.tiktok.get_campaign({
advertiser_id = "123456789",
campaign_id = "c001"
})
local campaign = result.data.list[1]
print(campaign.campaign_name)
print("Budget: " .. campaign.budget)
print("Status: " .. campaign.status)
list_advertisers
List advertisers accessible to the authenticated TikTok Business user.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
app_id | string | no | TikTok app ID to filter advertisers. |
secret | string | no | TikTok app secret to filter advertisers. |
Example
local result = app.integrations.tiktok.list_advertisers({})
for _, adv in ipairs(result.data.list) do
print(adv.advertiser_id .. " — " .. adv.name)
end
get_current_user
Get the authenticated user’s TikTok Business account information.
Parameters
None.
Example
local result = app.integrations.tiktok.get_current_user({})
print("Authenticated as: " .. result.data.display_name)
print("Email: " .. result.data.email)
Multi-Account Usage
If you have multiple TikTok accounts configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.tiktok.list_advertisers({})
-- Explicit default (portable across setups)
app.integrations.tiktok.default.list_advertisers({})
-- Named accounts
app.integrations.tiktok.work.list_campaigns({
advertiser_id = "123456789"
})
app.integrations.tiktok.brand_account.list_videos({
advertiser_id = "987654321"
})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# TikTok — Lua API Reference
## list_videos
List videos available for an advertiser in TikTok Business.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `advertiser_id` | string | yes | The TikTok advertiser ID. |
| `page` | integer | no | Page number for pagination. Defaults to 1. |
| `page_size` | integer | no | Number of videos per page. Defaults to 10. |
### Example
```lua
local result = app.integrations.tiktok.list_videos({
advertiser_id = "123456789",
page_size = 20
})
for _, video in ipairs(result.data.list) do
print(video.video_name .. " (ID: " .. video.video_id .. ")")
end
```
---
## get_video
Get details for a specific TikTok video, including preview URL, duration, and status.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `advertiser_id` | string | yes | The TikTok advertiser ID. |
| `video_id` | string | yes | The TikTok video ID. |
### Example
```lua
local result = app.integrations.tiktok.get_video({
advertiser_id = "123456789",
video_id = "v001"
})
print(result.data.video_name)
print("Duration: " .. result.data.duration .. "s")
print("Preview: " .. result.data.preview_url)
```
---
## upload_video
Upload a video to TikTok via URL for use in advertising campaigns.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `advertiser_id` | string | yes | The TikTok advertiser ID. |
| `video_url` | string | yes | URL of the video to upload (must be publicly accessible). |
| `file_name` | string | no | Custom name for the uploaded video file. |
### Example
```lua
local result = app.integrations.tiktok.upload_video({
advertiser_id = "123456789",
video_url = "https://example.com/videos/ad-creative.mp4",
file_name = "summer-campaign-creative"
})
print("Uploaded video ID: " .. result.video_id)
```
---
## list_campaigns
List advertising campaigns for a TikTok advertiser.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `advertiser_id` | string | yes | The TikTok advertiser ID. |
| `page` | integer | no | Page number for pagination. Defaults to 1. |
| `page_size` | integer | no | Number of campaigns per page. Defaults to 10. |
### Example
```lua
local result = app.integrations.tiktok.list_campaigns({
advertiser_id = "123456789",
page_size = 20
})
for _, campaign in ipairs(result.data.list) do
print(campaign.campaign_name .. " — Status: " .. campaign.status)
end
```
---
## get_campaign
Get details for a specific TikTok advertising campaign.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `advertiser_id` | string | yes | The TikTok advertiser ID. |
| `campaign_id` | string | yes | The TikTok campaign ID. |
### Example
```lua
local result = app.integrations.tiktok.get_campaign({
advertiser_id = "123456789",
campaign_id = "c001"
})
local campaign = result.data.list[1]
print(campaign.campaign_name)
print("Budget: " .. campaign.budget)
print("Status: " .. campaign.status)
```
---
## list_advertisers
List advertisers accessible to the authenticated TikTok Business user.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `app_id` | string | no | TikTok app ID to filter advertisers. |
| `secret` | string | no | TikTok app secret to filter advertisers. |
### Example
```lua
local result = app.integrations.tiktok.list_advertisers({})
for _, adv in ipairs(result.data.list) do
print(adv.advertiser_id .. " — " .. adv.name)
end
```
---
## get_current_user
Get the authenticated user's TikTok Business account information.
### Parameters
None.
### Example
```lua
local result = app.integrations.tiktok.get_current_user({})
print("Authenticated as: " .. result.data.display_name)
print("Email: " .. result.data.email)
```
---
## Multi-Account Usage
If you have multiple TikTok accounts configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.tiktok.list_advertisers({})
-- Explicit default (portable across setups)
app.integrations.tiktok.default.list_advertisers({})
-- Named accounts
app.integrations.tiktok.work.list_campaigns({
advertiser_id = "123456789"
})
app.integrations.tiktok.brand_account.list_videos({
advertiser_id = "987654321"
})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.tiktok.list_videos({advertiser_id = "example_advertiser_id", page = 1, page_size = 1})
print(result) Functions
list_videos Read
List videos available for an advertiser in TikTok Business. Returns video IDs, names, and metadata.
- Lua path
app.integrations.tiktok.list_videos- Full name
tiktok.tiktok_list_videos
| Parameter | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
page | integer | no | Page number for pagination. Defaults to 1. |
page_size | integer | no | Number of videos per page. Defaults to 10. |
get_video Read
Get details for a specific TikTok video, including preview URL, duration, and status.
- Lua path
app.integrations.tiktok.get_video- Full name
tiktok.tiktok_get_video
| Parameter | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
video_id | string | yes | The TikTok video ID. |
upload_video Write
Upload a video to TikTok via URL for use in advertising campaigns.
- Lua path
app.integrations.tiktok.upload_video- Full name
tiktok.tiktok_upload_video
| Parameter | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
video_url | string | yes | The URL of the video to upload (must be publicly accessible). |
file_name | string | no | A custom name for the uploaded video file. |
list_campaigns Read
List advertising campaigns for a TikTok advertiser. Returns campaign IDs, names, status, and budgets.
- Lua path
app.integrations.tiktok.list_campaigns- Full name
tiktok.tiktok_list_campaigns
| Parameter | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
page | integer | no | Page number for pagination. Defaults to 1. |
page_size | integer | no | Number of campaigns per page. Defaults to 10. |
get_campaign Read
Get details for a specific TikTok advertising campaign, including budget, schedule, and performance.
- Lua path
app.integrations.tiktok.get_campaign- Full name
tiktok.tiktok_get_campaign
| Parameter | Type | Required | Description |
|---|---|---|---|
advertiser_id | string | yes | The TikTok advertiser ID. |
campaign_id | string | yes | The TikTok campaign ID. |
list_advertisers Read
List advertisers accessible to the authenticated TikTok Business user. Returns advertiser IDs, names, and company details.
- Lua path
app.integrations.tiktok.list_advertisers- Full name
tiktok.tiktok_list_advertisers
| Parameter | Type | Required | Description |
|---|---|---|---|
app_id | string | no | The TikTok app ID to filter advertisers by. |
secret | string | no | The TikTok app secret to filter advertisers by. |
get_current_user Read
Get the authenticated user's TikTok Business account information, including display name, email, and status.
- Lua path
app.integrations.tiktok.get_current_user- Full name
tiktok.tiktok_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||