openapi: 3.0.0
info:
  title: Reddit User Posts API
  description: |
    The Reddit User Posts API returns the posts a Reddit user submitted, sorted by new, hot, top or controversial, with top limited to a time range. Posts the user pinned to their profile come first. NSFW posts are left out unless `safe` is `off`, and an NSFW profile returns an error unless `safe` is `off`. Reddit returns no posts for users who hide them from their profile, and a deleted, suspended or unknown account returns an error.

    Pages are cursor-based: pass `pagination.next_page_token` from one response as `next_page_token`, with the same `username`, `sort_by` and `time_period`, to get the next page. A page holds about 25 posts, and Reddit lists up to about 1,000 posts per sort.

    **Cross-linking**: pass the `author.username` of a Reddit Search or Reddit Post API result, or the `profile.username` from the Reddit User API, as `username`, and a post's `id` to the Reddit Post API as `post_id` for its content and top comments.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Reddit User Posts
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine to use
          schema:
            type: string
            enum: ["reddit_user_posts"]
            default: "reddit_user_posts"
        - name: username
          in: query
          required: true
          description: Reddit username, such as `spez`, or a link to the user's profile.
          schema:
            type: string
        - name: sort_by
          in: query
          required: false
          description: Order of the posts. Posts the user pinned to their profile come first.
          schema:
            type: string
            enum: ["new", "hot", "top", "controversial"]
            default: "new"
        - name: time_period
          in: query
          required: false
          description: Time range of the posts. Only accepted when `sort_by` is `top`. Reddit's default is `any_time`.
          schema:
            type: string
            enum: ["last_hour", "last_day", "last_week", "last_month", "last_year", "any_time"]
        - name: safe
          in: query
          required: false
          description: Set to `off` to include NSFW posts and the posts of an NSFW profile.
          schema:
            type: string
            enum: ["active", "off"]
            default: "active"
        - name: next_page_token
          in: query
          required: false
          description: Token for the next page of posts, from `pagination.next_page_token` of the previous response.
          schema:
            type: string
            pattern: '^dDNf[A-Za-z0-9+/]{2,40}={0,2}$'
      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.
          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
      properties:
        search_metadata:
          $ref: '#/components/schemas/SearchMetadata'
        search_parameters:
          $ref: '#/components/schemas/SearchParameters'
        error:
          type: string
          description: Error message explaining why no posts were returned.
        posts:
          type: array
          description: Posts the user submitted, in the order Reddit lists them.
          items:
            $ref: '#/components/schemas/Post'
        pagination:
          $ref: '#/components/schemas/Pagination'
    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: Reddit URL of the user's posts
        html_url:
          type: string
          description: URL to view HTML results
        json_url:
          type: string
          description: URL to view JSON results
    SearchParameters:
      type: object
      properties:
        engine:
          type: string
          description: Search engine used
        username:
          type: string
          description: Username of the user whose posts were listed
        sort_by:
          type: string
          description: Order of the posts
        time_period:
          type: string
          description: Time range of the posts
        safe:
          type: string
          description: NSFW filter setting
        next_page_token:
          type: string
          description: Token of the page requested
    Pagination:
      type: object
      properties:
        next_page_token:
          type: string
          description: Token to pass as `next_page_token` to get the next page of posts.
    Post:
      type: object
      required: [position, id, title, link, type, author, subreddit, score, upvote_ratio, comments, iso_date]
      properties:
        position:
          type: integer
          description: Position of the post on the page.
        id:
          type: string
          description: Reddit fullname of the post, prefixed with `t3_`.
        title:
          type: string
          description: Title of the post.
        link:
          type: string
          description: Link to the post on Reddit.
        type:
          type: string
          description: Kind of content the post holds, such as `text`, `image`, `video`, `gallery`, `link`, `poll` or `crosspost`.
        author:
          $ref: '#/components/schemas/PostAuthor'
        subreddit:
          $ref: '#/components/schemas/PostSubreddit'
        crosspost_parent:
          $ref: '#/components/schemas/PostCrosspostParent'
        score:
          type: integer
          description: Net vote score of the post.
        upvote_ratio:
          type: number
          description: Share of votes that are upvotes, between 0 and 1.
        comments:
          type: integer
          description: Number of comments on the post.
        awards_count:
          type: integer
          description: Number of awards the post has received.
        text:
          type: string
          description: Text of the post, with paragraphs separated by blank lines.
        text_links:
          type: array
          description: Links to pages outside Reddit found in the text of the post.
          items:
            type: string
        external_link:
          type: string
          description: Link to the page the post shares.
        domain:
          type: string
          description: Domain of the page the post shares.
        thumbnail:
          type: string
          description: Preview image Reddit shows for the post.
        image:
          type: string
          description: Image or GIF file uploaded with the post.
        images:
          type: array
          description: Gallery images of the post in display order.
          items:
            $ref: '#/components/schemas/PostImage'
        video:
          $ref: '#/components/schemas/PostVideo'
        poll:
          $ref: '#/components/schemas/PostPoll'
        distinguished:
          type: string
          description: Role the author posted with, such as `moderator` or `admin`.
        removed_by:
          type: string
          description: Who removed the post, `moderator` or `reddit`.
        iso_date:
          type: string
          format: date-time
          description: Date the post was created, in ISO 8601.
        is_nsfw:
          type: boolean
          description: Whether the post is marked NSFW.
        is_spoiler:
          type: boolean
          description: Whether the post is marked as a spoiler.
        is_pinned:
          type: boolean
          description: Whether the user pinned the post to their profile.
        is_locked:
          type: boolean
          description: Whether the post is locked for new comments.
        is_archived:
          type: boolean
          description: Whether the post is archived.
    PostAuthor:
      type: object
      required: [username, id, link]
      properties:
        username:
          type: string
          description: Username of the author.
        id:
          type: string
          description: Reddit fullname of the author, prefixed with `t2_`.
        link:
          type: string
          description: Link to the author's profile.
    PostSubreddit:
      type: object
      required: [name, id, link]
      properties:
        name:
          type: string
          description: Name of the subreddit the post was made in, `u_` and the username for a post made on the profile.
        id:
          type: string
          description: Reddit fullname of the subreddit, prefixed with `t5_`.
        link:
          type: string
          description: Link to the subreddit, or to the profile for a post made on it.
        icon:
          type: string
          description: Icon image of the subreddit.
        is_nsfw:
          type: boolean
          description: Whether the subreddit is marked NSFW.
    PostCrosspostParent:
      type: object
      required: [id, link]
      properties:
        id:
          type: string
          description: Reddit fullname of the original post, prefixed with `t3_`.
        title:
          type: string
          description: Title of the original post.
        link:
          type: string
          description: Link to the original post on Reddit.
    PostImage:
      type: object
      required: [image]
      properties:
        image:
          type: string
          description: Link to the largest version of the image Reddit shows.
        width:
          type: integer
          description: Width of the original image in pixels.
        height:
          type: integer
          description: Height of the original image in pixels.
    PostPoll:
      type: object
      required: [total_votes, choices]
      properties:
        total_votes:
          type: integer
          description: Number of votes the poll has received.
        choices:
          type: array
          description: Choices of the poll in the order Reddit shows them.
          items:
            $ref: '#/components/schemas/PostPollChoice'
        end_iso_date:
          type: string
          format: date-time
          description: Date the poll closes, in ISO 8601.
        is_closed:
          type: boolean
          description: Whether the poll is closed.
    PostPollChoice:
      type: object
      required: [text]
      properties:
        text:
          type: string
          description: Text of the choice.
        votes:
          type: integer
          description: Number of votes the choice received.
    PostVideo:
      type: object
      required: [hls_link]
      properties:
        link:
          type: string
          description: Link to the video as an MP4 file in its largest size.
        hls_link:
          type: string
          description: Link to the HLS playlist of the video.
        duration:
          type: integer
          description: Length of the video in seconds.
        width:
          type: integer
          description: Width of the MP4 file in pixels.
        height:
          type: integer
          description: Height of the MP4 file in pixels.
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
