openapi: 3.0.0
info:
  title: Facebook Events Search API
  description: |
    The Facebook Events Search API returns the public events Facebook's event search finds for a keyword in a
    city, or among online events, in Facebook's own order. An event carries its title, link and start time and,
    when Facebook shows them, its date as written, venue, picture, the counts of people interested and going,
    its price, and whether it is past, canceled, going on now or online.

    `location_id` names the city, and is required unless `is_online` is `true`. Facebook's event search also
    lists past events, so set `time_period_min` to keep them out. `time_period_min` and `time_period_max` keep
    the list to events that take place between those days, counted in the timezone Facebook assumes for the
    request, so an event close to midnight on either end can fall on either side. A recurring event matches when
    one of its occurrences falls in the period, and its row still shows its next occurrence. `category` keeps it
    to one of Facebook's event categories.

    A page lists about eight events. Each response carries a `pagination.next_page_token` while more events
    remain. Pass it back as `next_page_token` to fetch the next page. The token keeps the search on its own, so
    the other parameters may be omitted with it.

    `interested` and `going` are Facebook's own counts, which it rounds above 1,000 (22K is 22000). For a past
    event `going` counts the people who went. An event created in a Facebook group names it in `group`. A
    recurring event is one row for its whole series: `date` shows
    the next occurrence and `iso_date` the series' first start, so `iso_date` can come before `date`. `date`
    ends in "and N more" when more occurrences follow it.

    A search without events and a `next_page_token` Facebook no longer accepts answer 200 with an `error` and
    cost a credit.

    **Cross-linking**: an event's `link` is a valid `url` for the Facebook Event API, and its `id` a valid
    `event_id`. A city's `locations[].id` from the Facebook Location Search API, or its `venue.location_id` from the
    Facebook Event API, is a valid `location_id`.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Facebook Events Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["facebook_events_search"]
            default: "facebook_events_search"
        - name: q
          in: query
          required: false
          description: Keywords to search events for, such as jazz. Required unless next_page_token is provided.
          schema:
            type: string
            maxLength: 256
        - name: location_id
          in: query
          required: false
          description: >-
            Facebook id of the city to search, such as 106224666074625 for Austin, Texas: locations[].id from
            the Facebook Location Search API, or venue.location_id from the Facebook Event API. Required unless
            is_online is true or next_page_token is provided, and not sent together with is_online true.
          schema:
            type: string
            pattern: '^\s*[1-9][0-9]{0,18}\s*$'
        - name: is_online
          in: query
          required: false
          description: Set to true to search online events, which take no location_id.
          schema:
            type: boolean
        - name: category
          in: query
          required: false
          description: Event category to keep the list to.
          schema:
            type: string
            enum: [classics, comedy, crafts, dance, drinks, fitness_and_workouts, foods, games, gardening, health_and_medical, healthy_living_and_self_care, home_and_garden, music_and_audio, parties, professional_networking, religions, shopping, social_issues, sports, theater, tv_and_movies, visual_arts]
        - name: time_period_min
          in: query
          required: false
          description: >-
            First day events may take place on, as YYYY-MM-DD or MM/DD/YYYY, from 2020 to 2099. It can be used
            alone or with time_period_max.
          schema:
            type: string
            maxLength: 10
        - name: time_period_max
          in: query
          required: false
          description: >-
            Last day events may take place on, as YYYY-MM-DD or MM/DD/YYYY, from 2020 to 2099. Without
            time_period_min the window starts a year before it. It can be used alone or with time_period_min, and
            must not be before it.
          schema:
            type: string
            maxLength: 10
        - name: next_page_token
          in: query
          required: false
          description: >-
            Cursor for the next page, from pagination.next_page_token in a previous response. Other parameters
            sent with it must match the search it was issued for.
          schema:
            type: string
            maxLength: 8192
      responses:
        '200':
          description: >-
            Successful response. When Facebook finds no events, or no longer accepts the next_page_token, the
            body carries `error` in place of `events`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: >-
            Validation Error. There is an issue with query parameters, such as a missing q or location_id, a
            location_id together with is_online, a category or date Facebook does not take, or a next_page_token
            that is malformed or belongs to another search. 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'
        events:
          type: array
          description: Events on this page, in Facebook's order
          items:
            $ref: '#/components/schemas/Event'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Message naming why there are no events to show
    Event:
      type: object
      required: [position, id, title]
      properties:
        position:
          type: integer
          description: Position of the event on this page, starting at 1
        id:
          type: string
          description: Numeric id of the event
        title:
          type: string
          description: Title of the event
        link:
          type: string
          format: uri
          description: URL of the event on Facebook
        date:
          type: string
          description: Date and time as Facebook shows them, in the event's own timezone, or Happening now while Facebook counts the event as going on
        iso_date:
          type: string
          format: date-time
          description: Time the event starts, in UTC, or the first start of its series for a recurring event
        venue:
          $ref: '#/components/schemas/Venue'
        group:
          $ref: '#/components/schemas/Group'
        is_past:
          type: boolean
          description: Whether the event is over
        is_happening_now:
          type: boolean
          description: Whether the event is going on now, confirmed on the event's own page when Facebook labels it Happening now
        is_online:
          type: boolean
          description: Whether the event takes place online
        is_canceled:
          type: boolean
          description: Whether Facebook says the event was canceled.
        interested:
          type: integer
          description: Number of people interested, rounded above 1,000 as Facebook shows it (22K is 22000).
        going:
          type: integer
          description: Number of people going, or who went to a past event, rounded above 1,000 as Facebook shows it.
        price:
          type: string
          description: Price or price range as Facebook shows it, such as Free or £20 - £40
        thumbnail:
          type: string
          format: uri
          description: URL of the event's picture
        online_type:
          type: string
          description: How an online event is held, in lowercase, such as fb_live
        online_link:
          type: string
          format: uri
          description: Link of the outside service an online event is held on
    Venue:
      type: object
      properties:
        id:
          type: string
          description: Facebook id of the venue's Page
        name:
          type: string
          description: Name or address of the venue as the hosts entered it
    Group:
      type: object
      required: [id, link]
      properties:
        id:
          type: string
          description: Numeric id of the Facebook group the event was created in
        link:
          type: string
          format: uri
          description: URL of the group on Facebook
    Pagination:
      type: object
      properties:
        next_page_token:
          type: string
          description: Cursor for the next page
    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
          description: Facebook URL the search was sent to
        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: Keywords the events were searched for
        location_id:
          type: string
          description: City the events were searched in
        is_online:
          type: boolean
          description: Whether online events were searched
        category:
          type: string
          description: Category the list was kept to
        time_period_min:
          type: string
          description: First day of the requested time period
        time_period_max:
          type: string
          description: Last day of the requested time period
        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
