openapi: 3.0.0
info:
  title: Costco Search API
  description: |
    Search Costco's online stores in the United States, Canada, the United Kingdom, Mexico, Australia, Japan, South Korea, Taiwan, Iceland and New Zealand for products.

    Results carry the Costco product code, title and link, and, where Costco shows them, the image, price, price before a saving and the saving's end, price per unit, rating, review count, the promotions running, the labels Costco lists, the highlights on the product's card, the purchase minimum and limit, and the energy grade and English title on the sites that show them. They also say whether Costco shows the price only to signed-in members and, outside the United States and Canada, whether it sells the product only in its warehouses, whether it is sold out, offered in more options on its card or restricted in membership or shipping, and whether the price includes shipping. A price Costco hides from signed-out visitors is left out, with its saving and promotions. Prices are in the site's currency, as Costco shows them and as numbers.

    On costco.com and costco.ca, prices and stock are the ones Costco shows a shopper without a chosen location, in Seattle, WA and in Toronto, ON.

    The response lists the filters Costco offers for the search. Send an option's `filter_value` in `filters` to narrow the next search.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Costco Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: 'Search engine. Must be set to: `costco_search`'
          schema:
            type: string
            enum: ["costco_search"]
        - name: q
          in: query
          required: true
          description: Search text, up to 200 characters. Costco refuses some text, such as script tags or code. The search then returns an `error` and costs a credit.
          schema:
            type: string
            maxLength: 200
        - name: costco_domain
          in: query
          required: true
          description: Costco site to search. It sets the products, the language and the currency. Results on `costco.ca` are in English, except for a keyword it sends to one of its French pages.
          schema:
            type: string
            enum: ["costco.co.uk", "costco.com.mx", "costco.com.au", "costco.co.jp", "costco.co.kr", "costco.com.tw", "costco.is", "costco.co.nz", "costco.com", "costco.ca"]
        - name: sort_by
          in: query
          required: false
          description: Sorts the results. Each site offers its own sorts, `costco.co.uk` and `costco.is` all but `newest`, `costco.com.mx` and `costco.co.kr` all but `best_selling` and `newest`, `costco.com.au` all but `rating_low_to_high` and `newest`, `costco.co.jp` `best_match`, both price sorts, `rating_high_to_low` and `best_selling`, `costco.com.tw` `best_match` and both price sorts, `costco.co.nz` `best_match`, both price sorts and both name sorts, and `costco.com` and `costco.ca` `best_match`, both price sorts, `rating_high_to_low` and `newest`. Another sort returns a 400 error.
          schema:
            type: string
            enum: ["best_match", "price_low_to_high", "price_high_to_low", "rating_high_to_low", "rating_low_to_high", "best_selling", "name_a_to_z", "name_z_to_a", "newest"]
            default: "best_match"
        - name: filters
          in: query
          required: false
          description: Filters to apply, comma-separated, each a `filter_value` from the `filters` of an earlier response, such as `brand:Samsung,screenTechnology:QLED`, or `brands:Kirkland Signature,price:25-50` on `costco.com` and `costco.ca`. Values of one filter widen the results, and values of different filters narrow them. On `costco.com` and `costco.ca`, `price` and `rating` take one value each. Up to 10 values. A filter Costco does not offer for the search returns an error.
          schema:
            type: string
        - name: page
          in: query
          required: false
          description: Page of results, 24 products a page. The last page is the one whose `pagination` has no `next`.
          schema:
            type: integer
            minimum: 1
            maximum: 500
            default: 1
      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, or Costco couldn't run the search.
          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. We could not retrieve results in 90 seconds.
          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
      required: [search_metadata, search_parameters]
      properties:
        search_metadata:
          $ref: '#/components/schemas/SearchMetadata'
        search_parameters:
          $ref: '#/components/schemas/SearchParameters'
        search_information:
          $ref: '#/components/schemas/SearchInformation'
        organic_results:
          type: array
          description: Products Costco lists for the search, in Costco's order.
          items:
            $ref: '#/components/schemas/OrganicResult'
        filters:
          type: array
          description: Filters Costco offers for the search.
          items:
            $ref: '#/components/schemas/Filter'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Why the search returned no products.
    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: "Costco website page for this search, or the category or department page the website opens for its keyword"
        html_url:
          type: string
          description: "URL to view the raw results"
        json_url:
          type: string
          description: "URL to view JSON results"
    SearchParameters:
      type: object
      properties:
        engine:
          type: string
          description: Search engine used
        q:
          type: string
          description: The text searched for
        costco_domain:
          type: string
          description: Costco site searched
        sort_by:
          type: string
          description: Sort order
        filters:
          type: string
          description: Filters applied
        page:
          type: integer
          description: Page of results
    SearchInformation:
      type: object
      required: [query_displayed, total_results, currency]
      properties:
        query_displayed:
          type: string
          description: Search text as Costco read it.
        total_results:
          type: integer
          description: Number of products Costco reports for the search and its filters.
        did_you_mean:
          type: string
          description: Spelling Costco suggests for the search text.
        redirect_link:
          type: string
          description: Page Costco's website opens for this keyword instead of its search results, such as a category.
        currency:
          type: string
          description: ISO 4217 code of the site's currency.
    OrganicResult:
      type: object
      required: [position, product_id, title, link, is_price_hidden]
      properties:
        position:
          type: integer
          description: Position of the product on this page of results.
        product_id:
          type: string
          description: Costco's product code, the number at the end of the product link.
        title:
          type: string
          description: Product title, in the site's language.
        english_title:
          type: string
          description: English title Costco shows under the local title, on costco.co.jp, costco.co.kr and costco.com.tw.
        link:
          type: string
          description: Product page on the Costco site.
        thumbnail:
          type: string
          description: Product image.
        price:
          type: string
          description: Price as Costco shows it.
        extracted_price:
          type: number
          description: Numeric price, the lowest one when Costco shows a range.
        original_price:
          type: string
          description: Price before the saving, as Costco shows it.
        extracted_original_price:
          type: number
          description: Numeric price before the saving.
        savings:
          type: string
          description: Amount Costco takes off the price, as Costco shows it.
        extracted_savings:
          type: number
          description: Numeric amount Costco takes off the price.
        savings_ends_at:
          type: string
          format: date-time
          description: Time the saving ends, in UTC.
        unit_price:
          type: string
          description: Price per unit with its unit, as Costco shows it, such as "£43.75 per kg".
        extracted_unit_price:
          type: number
          description: Numeric price per unit.
        unit:
          type: string
          description: Unit the price per unit is for, in the site's language, such as "kg" or "100 g".
        rating:
          type: number
          description: Average rating out of 5.
        reviews:
          type: integer
          description: Number of reviews the rating is based on.
        promotions:
          type: array
          description: Offers running on the product at the time of the search, such as a reduction applied at checkout or the date a price is valid through.
          items:
            type: string
        badges:
          type: array
          description: Labels Costco shows on the product's card, such as "Online Only", "Hot Buy" or "Grocery Delivery".
          items:
            type: string
        highlights:
          type: array
          description: Points Costco lists in the product's summary on its card.
          items:
            type: string
        energy_rating:
          type: string
          description: Energy efficiency grade Costco shows, from A+++ to G.
        information_sheet_link:
          type: string
          description: Link to the product information sheet Costco publishes with the energy grade.
        min_quantity:
          type: integer
          description: Fewest units Costco lets a member buy, when that is more than one, as for a minimum or a pack sold in multiples.
        max_quantity:
          type: integer
          description: Most units Costco lets a member buy, when it sets a limit.
        is_price_hidden:
          type: boolean
          description: Whether Costco shows the price only to signed-in members.
        is_warehouse_only:
          type: boolean
          description: Whether Costco sells the product only in its warehouses, with no price online.
        is_out_of_stock:
          type: boolean
          description: Whether Costco shows the product as sold out.
        has_variants:
          type: boolean
          description: Whether the product's card in Costco's search offers other options, through More Options or two or more colour swatches.
        has_membership_restrictions:
          type: boolean
          description: Whether Costco limits the product to some membership types.
        has_shipping_restrictions:
          type: boolean
          description: Whether Costco limits where or how the product ships.
        is_free_shipping:
          type: boolean
          description: Whether Costco's price includes shipping.
    Filter:
      type: object
      required: [type, options]
      properties:
        type:
          type: string
          description: Filter name, in the site's language, such as "Brand".
        options:
          type: array
          description: Choices the filter offers.
          items:
            $ref: '#/components/schemas/FilterOption'
    FilterOption:
      type: object
      required: [text, filter_value, is_selected]
      properties:
        text:
          type: string
          description: Choice as Costco shows it.
        items:
          type: integer
          description: Number of products Costco reports for the choice.
        filter_value:
          type: string
          description: Code to send in `filters` to apply the choice.
        is_selected:
          type: boolean
          description: Whether the search applied the choice.
    Pagination:
      type: object
      required: [current, total_pages]
      properties:
        current:
          type: integer
          description: Current page.
        next:
          type: integer
          description: Next page number.
        total_pages:
          type: integer
          description: Number of pages Costco reports for the search.
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
