openapi: 3.0.0
info:
  title: Facebook Post API
  description: |
    The Facebook Post API returns one public Facebook post from its link. It accepts the links of Page,
    profile and group posts, videos, reels and photos, as well as facebook.com/share/ and fb.watch links.

    The `post` block carries the post's type, text with its hashtags and mentions, timestamp, author, the
    group for group posts, the reaction total with its breakdown by reaction type, the comment and share
    counts, views for videos and reels, and the images, video, link preview or original post it holds.
    Fields Facebook does not show for a post are left out.

    A post Facebook does not show publicly (deleted, private or visible to friends only) returns an
    `error` naming that. 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 the same `error` and costs a credit. So does an
    age-restricted post.

    **Cross-linking**: `post.link` is a valid `url` for the Facebook Comments API, which returns the post's
    comments and their replies.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Facebook Post
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["facebook_post"]
            default: "facebook_post"
        - name: url
          in: query
          required: true
          description: >-
            Link of the public Facebook post, such as
            https://www.facebook.com/NASA/posts/pfbid0e3VUx7RBHSKPcK7BSBpXZkY4iF5PwCSzWcB9z1gM7e5KKM9NhVj49vNNJ3Ckz24Ql.
            Page, profile and group post links, permalink.php links, video, watch and reel links, photo links,
            facebook.com/share/ links and fb.watch links are accepted.
          schema:
            type: string
            maxLength: 2048
      responses:
        '200':
          description: >-
            Successful response. When Facebook does not show the post publicly, the body carries `error` in
            place of `post`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: Validation Error. There is an issue with query parameters, such as a missing url or a link that is not a Facebook post.
          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'
        error:
          type: string
          description: Message saying Facebook does not show the post publicly
    Post:
      type: object
      required: [id, link, type, iso_date, author, reactions, comments]
      properties:
        id:
          type: string
          description: Numeric id of the post, or of the video or photo for a video, reel or photo link
        link:
          type: string
          format: uri
          description: URL of the post on Facebook
        type:
          type: string
          enum: [text, photo, carousel, video, reel, link, shared]
          description: Kind of post, read from what it holds
        text:
          type: string
          description: Text of the post
        hashtags:
          type: array
          description: Hashtags in the text as written, without the hash sign
          items:
            type: string
        mentions:
          type: array
          description: Pages and people tagged in the text
          items:
            $ref: '#/components/schemas/Mention'
        iso_date:
          type: string
          format: date-time
          description: Time the post was published, in UTC
        author:
          $ref: '#/components/schemas/Author'
        group:
          $ref: '#/components/schemas/Group'
        reactions:
          type: integer
          description: Total number of reactions
        reactions_breakdown:
          $ref: '#/components/schemas/ReactionsBreakdown'
        comments:
          type: integer
          description: Number of comments, replies included
        shares:
          type: integer
          description: Number of shares, which Facebook does not show for videos and rounds for popular reels
        views:
          type: integer
          description: Number of views of a video or reel
        images:
          type: array
          description: Photos the post holds
          items:
            $ref: '#/components/schemas/Photo'
        video:
          $ref: '#/components/schemas/Video'
        link_preview:
          $ref: '#/components/schemas/LinkPreview'
        shared_post:
          $ref: '#/components/schemas/SharedPost'
    Author:
      type: object
      description: Page or person who posted
      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
    Group:
      type: object
      description: Group the post was published in
      required: [id, name, link]
      properties:
        id:
          type: string
          description: Numeric id of the group
        name:
          type: string
          description: Name of the group
        link:
          type: string
          format: uri
          description: URL of the group
    ReactionsBreakdown:
      type: object
      description: Reactions by type, for the types the post 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
    Photo:
      type: object
      required: [id, link, image]
      properties:
        id:
          type: string
          description: Numeric id of the photo
        link:
          type: string
          format: uri
          description: URL of the photo on Facebook
        image:
          type: string
          format: uri
          description: URL of the image file
        width:
          type: integer
          description: Width of the image in pixels
        height:
          type: integer
          description: Height of the image in pixels
        accessibility_caption:
          type: string
          description: Description of the image that Facebook gives screen readers
    Video:
      type: object
      required: [id, link]
      properties:
        id:
          type: string
          description: Numeric id of the video
        permalink:
          type: string
          format: uri
          description: URL of the video or reel on Facebook
        link:
          type: string
          format: uri
          description: URL of the best video file Facebook offers for download, which can be a lower quality than it streams
        thumbnail:
          type: string
          format: uri
          description: URL of the video's cover image
        duration:
          type: number
          description: Length of the video in seconds
        width:
          type: integer
          description: Width of the video in pixels
        height:
          type: integer
          description: Height of the video in pixels
        sd_link:
          type: string
          format: uri
          description: URL of the standard-definition video file
        hd_link:
          type: string
          format: uri
          description: URL of the high-definition video file
        dash_manifest_link:
          type: string
          format: uri
          description: URL of the video's DASH manifest
    LinkPreview:
      type: object
      description: Preview of the web page the post links to
      required: [link]
      properties:
        title:
          type: string
          description: Title of the linked page
        link:
          type: string
          format: uri
          description: URL of the linked page
        source:
          type: string
          description: Domain of the linked page
        description:
          type: string
          description: Summary of the linked page
        thumbnail:
          type: string
          format: uri
          description: URL of the preview image
    SharedPost:
      type: object
      description: Original post that this post shares
      properties:
        id:
          type: string
          description: Numeric id of the original post
        link:
          type: string
          format: uri
          description: URL of the original post
        type:
          type: string
          enum: [text, photo, carousel, video, reel, link, shared]
          description: Kind of the original post
        text:
          type: string
          description: Text of the original post
        hashtags:
          type: array
          description: Hashtags in the original post's text
          items:
            type: string
        mentions:
          type: array
          description: Pages and people tagged in the original post's text
          items:
            $ref: '#/components/schemas/Mention'
        iso_date:
          type: string
          format: date-time
          description: Time the original post was published, in UTC
        author:
          $ref: '#/components/schemas/Author'
        group:
          $ref: '#/components/schemas/Group'
        images:
          type: array
          description: Photos the original post holds
          items:
            $ref: '#/components/schemas/Photo'
        video:
          $ref: '#/components/schemas/Video'
        link_preview:
          $ref: '#/components/schemas/LinkPreview'
    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 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
      required: [engine]
      properties:
        engine:
          type: string
          description: Search engine identifier
        url:
          type: string
          description: Post link the search was requested with
        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
