API Overview

The TikTok API provides powerful search capabilities for discovering TikTok content, including keyword-based searches and trending content discovery across multiple countries.

Overview

The TikTok service offers two primary capabilities:
  • Query Search: Search TikTok content based on keywords or hashtags
  • Trending Search: Discover trending TikTok content sorted by various engagement metrics
The TikTok API requires an Apify API key to function. Ensure this environment variable is set before making any requests.

Job Types

searchbyquery

Searches TikTok content based on keywords, hashtags, or phrases. This job type allows you to find specific content across the TikTok platform. Use Cases:
  • Finding content about specific topics
  • Discovering videos with certain hashtags
  • Researching content trends for particular keywords

searchbytrending

Retrieves trending TikTok content sorted by various engagement metrics. This job type helps you discover what’s currently popular on TikTok. Use Cases:
  • Monitoring viral content
  • Tracking engagement trends
  • Analyzing popular content by country
  • Understanding what content formats are gaining traction

Parameters

Common Parameters

ParameterTypeRequiredDefaultDescription
typestringYes-The job type: searchbyquery or searchbytrending
max_itemsintegerNo10Maximum number of items to return

searchbyquery Parameters

ParameterTypeRequiredDefaultDescription
searcharray[string]Yes-Array of search queries (keywords or hashtags)

searchbytrending Parameters

ParameterTypeRequiredDefaultDescription
sort_bystringNovvSort trending content by metric. See Sort Options
periodstringNo7Time period for trending content: "7" (week) or "30" (month)
country_codestringNo"US"Country code for regional trending content. See Supported Countries

Sort Options

The sort_by parameter for trending searches supports the following values:
ValueDescriptionBest For
vvSort by views/trending scoreFinding viral content
likeSort by number of likesHigh engagement content
commentSort by number of commentsDiscussion-generating content
repostSort by number of reposts/sharesHighly shareable content

API Examples

Search by Query

{
  "type": "tiktok",
  "arguments": {
    "type": "searchbyquery",
    "search": ["AI", "crypto"],
    "max_items": 10
  }
}
{
  "type": "tiktok",
  "arguments": {
    "type": "searchbyquery",
    "search": ["#artificialintelligence", "#machinelearning", "#tech"],
    "max_items": 25
  }
}
{
  "type": "tiktok",
  "arguments": {
    "type": "searchbyquery",
    "search": [
      "sustainable fashion",
      "eco friendly clothing",
      "thrift haul"
    ],
    "max_items": 50
  }
}

Most Shared Content (Last Week)

{
  "type": "tiktok",
  "arguments": {
    "type": "searchbytrending",
    "sort_by": "repost",
    "period": "7",
    "max_items": 10
  }
}

Most Commented Videos (Last Month)

{
  "type": "tiktok",
  "arguments": {
    "type": "searchbytrending",
    "sort_by": "comment",
    "period": "30",
    "max_items": 20
  }
}
{
  "type": "tiktok",
  "arguments": {
    "type": "searchbytrending",
    "sort_by": "vv",
    "period": "7",
    "country_code": "JP",
    "max_items": 15
  }
}

Most Liked Content by Country

{
  "type": "tiktok",
  "arguments": {
    "type": "searchbytrending",
    "sort_by": "like",
    "period": "7",
    "country_code": "BR",
    "max_items": 25
  }
}

Use Case Examples

Content Research

Discover what topics are gaining traction:
{
  "type": "tiktok",
  "arguments": {
    "type": "searchbyquery",
    "search": ["climate change", "sustainability", "green energy"],
    "max_items": 30
  }
}

Competitive Analysis

Monitor trending content in specific markets:
{
  "type": "tiktok",
  "arguments": {
    "type": "searchbytrending",
    "sort_by": "vv",
    "period": "7",
    "country_code": "KR",
    "max_items": 20
  }
}

Engagement Analysis

Find highly engaging content formats:
{
  "type": "tiktok",
  "arguments": {
    "type": "searchbytrending",
    "sort_by": "comment",
    "period": "30",
    "country_code": "US",
    "max_items": 50
  }
}

Supported Countries

The TikTok API supports trending content from the following countries:

Americas

  • US - United States
  • CA - Canada
  • BR - Brazil

Europe

  • GB - United Kingdom
  • FR - France
  • DE - Germany
  • IT - Italy
  • ES - Spain
  • RU - Russia
  • TR - Turkey

Asia-Pacific

  • AU - Australia
  • JP - Japan
  • KR - South Korea
  • SG - Singapore
  • MY - Malaysia
  • ID - Indonesia
  • TH - Thailand
  • PH - Philippines
  • VN - Vietnam
  • TW - Taiwan
  • IL - Israel

Middle East & Africa

  • AE - United Arab Emirates
  • SA - Saudi Arabia
  • EG - Egypt

Best Practices

1. Query Optimization

  • Use specific keywords for targeted results
  • Combine related search terms in a single request
  • Include both general terms and specific hashtags
  • Use period: "7" for current trends
  • Use period: "30" for more stable trend analysis
  • Compare different sort_by metrics to understand content performance

3. Regional Insights

  • Always specify country_code when analyzing regional markets
  • Compare trending content across different countries
  • Consider cultural context when interpreting results

4. Data Collection

  • Set appropriate max_items based on your analysis needs
  • For comprehensive analysis, consider multiple queries with different parameters
  • Cache results to avoid redundant API calls

Response Data

While the exact response structure may vary, typical TikTok data includes:
  • Video Details: Title, description, hashtags, duration
  • Engagement Metrics: Views, likes, comments, shares/reposts
  • Creator Information: Username, follower count
  • Timestamps: Creation date, trending period
  • Media URLs: Video URLs, thumbnail images
  • Audio Information: Music/sound used in the video

Limitations

  • Search results are subject to TikTok’s algorithm and availability
  • Historical trending data is limited to 7 or 30-day periods
  • Country-specific trending may not reflect global trends
  • Content availability may vary by region
  • Maximum item limits apply to prevent excessive API usage

Error Handling

Common Error Scenarios

Invalid Country Code

Ensure the country_code parameter uses one of the supported country codes listed above.

Invalid Sort Option

The sort_by parameter must be one of: vv, like, comment, or repost.

Invalid Period

The period parameter only accepts "7" or "30" as string values.

Missing Required Parameters

  • searchbyquery requires the search array
  • searchbytrending has all optional parameters but benefits from explicit configuration

Notes

  • The vv sort option represents TikTok’s trending/view score algorithm
  • Period values must be strings ("7" not 7)
  • Search queries can include hashtags with or without the # symbol
  • Multiple search terms in the search array will return combined results