openapi: 3.0.0
info:
  title: Facebook Marketplace API
  description: |
    The Facebook Marketplace API searches the listings on Facebook Marketplace around a place.

    Pass the place as `location_id`, the city name or numeric place id in a Marketplace link, or as `lat` and
    `lon`. Each response lists up to about 24 listings with title, price, price before a reduction, photo,
    location, delivery options, sold and pending state and time listed, and carries
    `pagination.next_page_token` while Facebook offers more. Facebook widens a search to less similar listings
    on later pages, and a listing can come back on a later page.

    A place Facebook does not know, and a `next_page_token` Facebook no longer accepts, answer 200 with an
    `error` and cost a credit.

    **Cross-linking**: `organic_results[].item_id` is a valid `item_id` for the Facebook Marketplace Item API.
    `organic_results[].location.id` is a valid `location_id` here, and `organic_results[].category_id` a valid
    `category_id`.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Facebook Marketplace
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["facebook_marketplace"]
            default: "facebook_marketplace"
        - name: q
          in: query
          required: false
          description: What to search for. Required unless next_page_token is provided.
          schema:
            type: string
            maxLength: 250
        - name: location_id
          in: query
          required: false
          description: >-
            The place to search around, as the city name or numeric place id in a Facebook Marketplace link, such as
            austin or 106224666074625, or organic_results[].location.id from a previous response. Required unless lat
            and lon, or next_page_token, are provided.
          schema:
            type: string
            maxLength: 50
            pattern: '^(?!(category|create|directory|np|profile)$)([A-Za-z][A-Za-z0-9_-]{1,49}|[1-9][0-9]{4,18})$'
        - name: lat
          in: query
          required: false
          description: Latitude of the place to search around. Pass it with lon, in place of location_id.
          schema:
            type: number
            minimum: -90
            maximum: 90
        - name: lon
          in: query
          required: false
          description: Longitude of the place to search around. Pass it with lat, in place of location_id.
          schema:
            type: number
            minimum: -180
            maximum: 180
        - name: sort_by
          in: query
          required: false
          description: >-
            Order of the listings. best_match (default) is Facebook's own order, newest lists the latest first,
            price_low_to_high and price_high_to_low go by price, and distance lists the nearest first.
          schema:
            type: string
            enum: [best_match, newest, price_low_to_high, price_high_to_low, distance]
            default: best_match
        - name: price_min
          in: query
          required: false
          description: >-
            Lowest price in whole units of the local currency. Cannot be greater than price_max. A positive minimum
            can exclude listings above 21,474,836 even without a maximum. Omit both price filters or pass only
            price_min=0 to see higher prices.
          schema:
            type: integer
            minimum: 0
            maximum: 21474836
        - name: price_max
          in: query
          required: false
          description: Highest price, as a whole number in the currency of the place. 0 lists free items.
          schema:
            type: integer
            minimum: 0
            maximum: 21474836
        - name: condition
          in: query
          required: false
          description: >-
            Condition of the item, as one or more of new, used_like_new, used_good and used_fair separated by commas,
            each at most once.
          schema:
            type: string
            pattern: '^(new|used_like_new|used_good|used_fair)(,(new|used_like_new|used_good|used_fair)){0,3}$'
        - name: delivery_method
          in: query
          required: false
          description: How the buyer gets the item. Facebook offers shipping in some countries only.
          schema:
            type: string
            enum: [local_pickup, shipping]
        - name: availability
          in: query
          required: false
          description: available (default) lists items for sale, and sold lists items that are sold or pending.
          schema:
            type: string
            enum: [available, sold]
            default: available
        - name: time_period
          in: query
          required: false
          description: >-
            When the item was listed, through Facebook's own filter for the last 24 hours, 7 days and 30 days. Facebook
            can add older listings.
          schema:
            type: string
            enum: [last_day, last_week, last_month]
        - name: category_id
          in: query
          required: false
          description: Facebook category to keep to, from organic_results[].category_id in a previous response.
          schema:
            type: string
            pattern: '^[1-9][0-9]{0,18}$'
        - name: next_page_token
          in: query
          required: false
          description: >-
            Cursor for the next page, from pagination.next_page_token in a previous response. The token identifies the
            search on its own, so the other parameters may be omitted, and any sent with it must match the search it
            came from.
          schema:
            type: string
            maxLength: 8192
      responses:
        '200':
          description: >-
            Successful response. When Facebook has no listings, does not know the location_id, or no longer accepts
            the next_page_token, the body carries `error` naming the reason in place of `organic_results`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: >-
            Validation Error. There is an issue with query parameters, such as a missing place, a price that is not a
            whole number, or a malformed next_page_token. The search is not billed.
          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 Facebook answered but returned nothing usable. 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'
        search_information:
          $ref: '#/components/schemas/SearchInformation'
        organic_results:
          type: array
          description: Listings on this page
          items:
            $ref: '#/components/schemas/Listing'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Message naming why there are no listings to show
    SearchInformation:
      type: object
      description: What Facebook searched, on the first page of a search by location_id
      required: [location]
      properties:
        location:
          $ref: '#/components/schemas/SearchLocation'
    SearchLocation:
      type: object
      description: The place Facebook searched around
      required: [id, latitude, longitude]
      properties:
        id:
          type: string
          description: Numeric Facebook id of the place
        name:
          type: string
          description: Name of the place
        latitude:
          type: number
          description: Latitude Facebook searched around
        longitude:
          type: number
          description: Longitude Facebook searched around
    Listing:
      type: object
      required: [position, item_id, title, link]
      properties:
        position:
          type: integer
          description: Position of the listing on this page, starting at 1
        item_id:
          type: string
          description: Numeric Facebook id of the item
        title:
          type: string
          description: Title of the listing
        link:
          type: string
          format: uri
          description: URL of the item on Facebook Marketplace
        price:
          type: string
          description: Price as Facebook shows it
        extracted_price:
          type: number
          description: Price as a number, 0 for a free item
        original_price:
          type: string
          description: Price before the seller lowered it, as Facebook shows it
        extracted_original_price:
          type: number
          description: Price before the seller lowered it, as a number
        extensions:
          type: array
          description: Lines Facebook shows below the title, such as a vehicle's mileage or a rental's address
          items:
            type: string
        category_id:
          type: string
          description: Numeric Facebook id of the item's category
        delivery_options:
          type: array
          description: >-
            Ways to get the item, among in_person, public_meetup, door_pickup, door_dropoff, shipping_onsite and
            shipping_offsite
          items:
            type: string
        location:
          $ref: '#/components/schemas/ListingLocation'
        iso_date:
          type: string
          format: date-time
          description: Time the item was listed, in UTC
        is_sold:
          type: boolean
          description: Whether the item is sold
        is_pending:
          type: boolean
          description: Whether a sale of the item is pending
        is_partner_listing:
          type: boolean
          description: Whether the item is listed by a partner of Facebook, such as eBay
        has_video:
          type: boolean
          description: Whether the listing carries a video
        seller:
          $ref: '#/components/schemas/Seller'
        thumbnail:
          type: string
          format: uri
          description: URL of the listing's first photo
    ListingLocation:
      type: object
      description: Where the item is
      properties:
        id:
          type: string
          description: Numeric Facebook id of the place
        name:
          type: string
          description: Name of the place
        city:
          type: string
          description: City
        state:
          type: string
          description: State or region code
    Seller:
      type: object
      description: The Page that lists the item, for a listing by a partner of Facebook
      properties:
        id:
          type: string
          description: Numeric Facebook id of the Page
        name:
          type: string
          description: Name of the Page
    Pagination:
      type: object
      properties:
        next_page_token:
          type: string
          description: Cursor for the next page of the same search
    SearchMetadata:
      type: object
      required: [status, created_at]
      properties:
        id:
          type: string
          description: Unique identifier for the search request, absent when zero_retention is set
        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
          nullable: true
          description: Facebook URL of the search, when it was requested with a location_id
        html_url:
          type: string
          description: URL to view HTML results
        json_url:
          type: string
          description: URL to view JSON results
    SearchParameters:
      type: object
      required: [engine]
      properties:
        engine:
          type: string
          description: Search engine identifier
        q:
          type: string
          description: Query the listings were requested for
        location_id:
          type: string
          description: Place the listings were requested around
        lat:
          type: number
          description: Latitude the listings were requested around
        lon:
          type: number
          description: Longitude the listings were requested around
        sort_by:
          type: string
          description: Order the listings were requested in
        price_min:
          type: integer
          description: Lowest price requested
        price_max:
          type: integer
          description: Highest price requested
        condition:
          type: string
          description: Conditions requested
        delivery_method:
          type: string
          description: Delivery method requested
        availability:
          type: string
          description: Availability requested
        time_period:
          type: string
          description: Listing age requested
        category_id:
          type: string
          description: Category requested
        next_page_token:
          type: string
          description: Cursor of the requested page
        zero_retention:
          type: boolean
          description: Whether zero data retention was requested
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
