openapi: 3.0.0
info:
  title: TikTok Shop Search API
  description: |
    The TikTok Shop Search API returns the product listings TikTok Shop shows for a keyword, up to 30 per page,
    with prices, ratings, units sold, the selling shop and the badges on each card. It searches the US store by
    default and the Brazil, Indonesia, Japan, Mexico, Malaysia, Philippines, Singapore, Thailand or Vietnam store
    with `country`. Results can be
    ordered by relevance or by best sellers and paged with `next_page_token`.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: TikTok Shop Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["tiktok_shop_search"]
            default: "tiktok_shop_search"
        - name: q
          in: query
          required: false
          description: Keyword to search TikTok Shop for (e.g., "wireless earbuds"), up to 100 characters. Required unless next_page_token is given, which carries it.
          schema:
            type: string
            maxLength: 100
        - name: sort_by
          in: query
          required: false
          description: Order of the results, relevance or TikTok Shop's best sellers order. A new search defaults to relevance; with next_page_token, the token's order applies. best_selling is available when country is US, MY, PH, SG, TH or VN.
          schema:
            type: string
            enum: ["relevance", "best_selling"]
        - name: country
          in: query
          required: false
          description: Two-letter code of the country whose TikTok Shop store to search; products, prices and currency are those of that store. A new search defaults to US; with next_page_token, the token's country applies.
          schema:
            type: string
            enum: ["US", "BR", "ID", "JP", "MX", "MY", "PH", "SG", "TH", "VN"]
        - name: next_page_token
          in: query
          required: false
          description: Token from pagination.next_page_token that returns the next page; it keeps the q, sort_by and country it was issued for
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: Validation Error. There is an issue with query parameters, such as missing required parameters or invalid values.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication Error. The API key is missing or invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate Limit Exceeded. The number of allowed requests has been exceeded. Consider upgrading your plan or waiting for the limit to reset.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Server Error. Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: >-
            Timeout, or TikTok Shop answered but returned nothing usable. The body is a bare
            {"error": ...} rather than a search response, and the search is not billed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: 'Use Bearer authentication. Format: "Bearer YOUR_API_KEY"'
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api_key
      description: Pass API key as query parameter
  schemas:
    SearchResponse:
      type: object
      properties:
        search_metadata:
          $ref: '#/components/schemas/SearchMetadata'
        search_parameters:
          $ref: '#/components/schemas/SearchParameters'
        organic_results:
          type: array
          items:
            $ref: '#/components/schemas/Product'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Error message when TikTok Shop returned no products for the query
    Product:
      type: object
      required: [position, product_id, title, link, price, extracted_price, currency, seller, thumbnail]
      properties:
        position:
          type: integer
          description: Position of the product on this page, starting at 1
        product_id:
          type: string
          description: TikTok Shop's identifier of the product
        title:
          type: string
          description: Product title
        link:
          type: string
          description: URL of the product page on TikTok Shop
        brand:
          type: string
          description: Brand name of the product
        price:
          type: string
          description: Price as displayed in the store's currency, with a "From" prefix when variants differ in price (e.g., "$18.93", "From $9.09", "S$7.60")
        extracted_price:
          type: number
          description: Price as a number, the starting price when price has a "From" prefix
        original_price:
          type: string
          description: Crossed-out price as displayed
        extracted_original_price:
          type: number
          description: Crossed-out price as a number
        discount_percentage:
          type: integer
          description: Discount off the crossed-out price, in percent
        currency:
          type: string
          description: Currency code of the prices (e.g., "USD", "SGD")
        rating:
          type: number
          description: Average star rating out of 5
        reviews:
          type: integer
          description: Number of reviews
        items_sold:
          type: integer
          description: Number of units sold
        seller:
          $ref: '#/components/schemas/Seller'
        badges:
          type: array
          items:
            type: string
          description: Labels shown on the product card (e.g., "Free shipping")
        thumbnail:
          type: string
          description: URL of the product image
    Seller:
      type: object
      required: [id, name]
      properties:
        id:
          type: string
          description: TikTok Shop's identifier of the shop
        name:
          type: string
          description: Shop name
        thumbnail:
          type: string
          description: URL of the shop logo
        is_verified:
          type: boolean
          description: Whether TikTok Shop marks the shop as verified
    Pagination:
      type: object
      properties:
        next_page_token:
          type: string
          description: Token to pass as next_page_token for the next page of results
    SearchMetadata:
      type: object
      required: [status, created_at]
      properties:
        id:
          type: string
          description: Unique identifier for the search request
        status:
          type: string
          description: Status of the search request
        created_at:
          type: string
          format: date-time
          description: Timestamp when the search was created
        request_time_taken:
          type: number
          description: Time taken to make the request in seconds
        parsing_time_taken:
          type: number
          description: Time taken to parse the results in seconds
        total_time_taken:
          type: number
          description: Total time taken for the search in seconds
        request_url:
          type: string
          description: TikTok Shop URL for this search
        html_url:
          type: string
          description: URL to view HTML results
        json_url:
          type: string
          description: URL to view JSON results
    SearchParameters:
      type: object
      properties:
        engine:
          type: string
          description: Search engine identifier
        q:
          type: string
          description: Keyword searched
        sort_by:
          type: string
          description: Order of the results
        country:
          type: string
          description: Country code of the store searched
        next_page_token:
          type: string
          description: Token of the page requested
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
