openapi: 3.0.0
info:
  title: Facebook Comments API
  description: |
    The Facebook Comments API returns the comments on a public Facebook post, video, reel or photo, ten
    at a time, or the replies to one of its comments.

    `sort_by` picks the order. `most_relevant`, the default, is Facebook's ranked view and can leave some
    comments out. When it lists none for a post that has comments, they come back oldest first. `newest`
    and `oldest` list the comments by date. Each response carries a
    `pagination.next_page_token` while more remain. Pass it back as `next_page_token` to fetch the next
    page. The token identifies the post and the order on its own, so `url` may be omitted with it.
    A `next_page_token` Facebook no longer accepts answers 200 with an `error` and costs a credit.

    Each comment includes its text, attached image, timestamp, link, author, the reaction total with its
    breakdown by reaction type and its reply count. A comment with replies carries a
    `replies_next_page_token`. Pass it as `next_page_token` to list the replies, and the response then
    carries `parent_comment`. Replies come in thread order, and a reply to another reply names it in
    `reply_to`.

    A share or fb.watch link that opens a profile, Page, event, Marketplace item or group, or a dead
    fb.watch link, answers 200 with an `error` and costs a credit. So does an age-restricted post.

    **Cross-linking**: `post.link` from the Facebook Post API is a valid `url` here.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Facebook Comments
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["facebook_comments"]
            default: "facebook_comments"
        - name: url
          in: query
          required: false
          description: >-
            Link of the public Facebook post, video, reel or photo, such as
            https://www.facebook.com/NASA/posts/pfbid0e3VUx7RBHSKPcK7BSBpXZkY4iF5PwCSzWcB9z1gM7e5KKM9NhVj49vNNJ3Ckz24Ql,
            or post.link from the Facebook Post API. Share and fb.watch links are accepted. Required unless
            next_page_token is provided.
          schema:
            type: string
            maxLength: 2048
        - name: sort_by
          in: query
          required: false
          description: >-
            Order of the comments. most_relevant (default) is Facebook's ranked view and can leave some
            comments out. When it lists none for a post that has comments, they come back oldest first. newest
            lists the latest first and oldest the earliest first. With a
            next_page_token it must match the order the token was issued for, and it cannot be combined with
            a replies_next_page_token.
          schema:
            type: string
            enum: [most_relevant, newest, oldest]
        - name: next_page_token
          in: query
          required: false
          description: >-
            Cursor for the next page, from pagination.next_page_token in a previous response, or a comment's
            replies_next_page_token to list its replies. Omit it for the first page.
          schema:
            type: string
            maxLength: 8192
      responses:
        '200':
          description: >-
            Successful response. When Facebook does not show the post publicly, the post or comment has no
            comments or replies, or Facebook no longer accepts the next_page_token, the body carries `error`
            naming the reason in place of `comments`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: >-
            Validation Error. There is an issue with query parameters, such as a link that is not a Facebook
            post, a malformed next_page_token, or a sort_by that does not match the 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'
        post:
          $ref: '#/components/schemas/Post'
        parent_comment:
          $ref: '#/components/schemas/ParentComment'
        comments:
          type: array
          description: Comments on the post for this page, or the replies to the parent comment
          items:
            $ref: '#/components/schemas/Comment'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Message naming why there are no comments to show
    Post:
      type: object
      description: The post whose comments are listed, on the first page only
      required: [link, comments]
      properties:
        link:
          type: string
          format: uri
          description: URL of the post on Facebook
        comments:
          type: integer
          description: Number of comments on the post, replies included
    ParentComment:
      type: object
      description: The comment whose replies are listed
      required: [id]
      properties:
        id:
          type: string
          description: Numeric id of the comment
    Comment:
      type: object
      required: [position, id, iso_date, link, author, reactions, replies]
      properties:
        position:
          type: integer
          description: Position of the comment on this page, starting at 1
        id:
          type: string
          description: Numeric id of the comment
        text:
          type: string
          description: Text of the comment
        mentions:
          type: array
          description: Pages and people tagged in the text
          items:
            $ref: '#/components/schemas/Mention'
        image:
          type: string
          format: uri
          description: URL of the photo, sticker or GIF the comment was posted with
        iso_date:
          type: string
          format: date-time
          description: Time the comment was posted, in UTC
        link:
          type: string
          format: uri
          description: URL of the comment on Facebook
        author:
          $ref: '#/components/schemas/Author'
        reply_to:
          $ref: '#/components/schemas/ReplyTo'
        reactions:
          type: integer
          description: Total number of reactions to the comment
        reactions_breakdown:
          $ref: '#/components/schemas/ReactionsBreakdown'
        replies:
          type: integer
          description: Number of replies to the comment
        replies_next_page_token:
          type: string
          description: Token to pass as next_page_token to list the comment's replies
    Author:
      type: object
      description: Page or person who wrote the comment
      required: [id, name]
      properties:
        id:
          type: string
          description: Facebook id of the author
        name:
          type: string
          description: Display name of the author
        username:
          type: string
          description: Username in the author's profile link
        link:
          type: string
          format: uri
          description: URL of the author's Facebook profile or Page
        avatar:
          type: string
          format: uri
          description: URL of the author's profile picture
        is_verified:
          type: boolean
          description: Whether the author's Page or profile is verified
    Mention:
      type: object
      required: [id, name]
      properties:
        id:
          type: string
          description: Facebook id of the Page or person
        name:
          type: string
          description: Name as written in the text
        link:
          type: string
          format: uri
          description: URL of the Page or profile
    ReplyTo:
      type: object
      description: The reply this reply answers
      required: [id]
      properties:
        id:
          type: string
          description: Numeric id of the reply it answers
        name:
          type: string
          description: Display name of that reply's author
    ReactionsBreakdown:
      type: object
      description: Reactions by type, for the types the comment received
      properties:
        like:
          type: integer
          description: Like reactions
        love:
          type: integer
          description: Love reactions
        care:
          type: integer
          description: Care reactions
        haha:
          type: integer
          description: Haha reactions
        wow:
          type: integer
          description: Wow reactions
        sad:
          type: integer
          description: Sad reactions
        angry:
          type: integer
          description: Angry reactions
    Pagination:
      type: object
      properties:
        next_page_token:
          type: string
          description: Cursor for the next page of the same list
    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 post, when the search was requested with a url
        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
        url:
          type: string
          description: Post link the comments were requested with
        sort_by:
          type: string
          description: Order the comments were requested in
        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
