beehiiv subpackage_polls API

The subpackage_polls API from beehiiv — 3 operation(s) for subpackage_polls.

OpenAPI Specification

beehiiv-subpackage-polls-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: API Reference subpackage_advertisement_opportunities subpackage_polls API
  version: 1.0.0
servers:
- url: https://api.beehiiv.com/v2
tags:
- name: subpackage_polls
paths:
  /publications/{publicationId}/polls:
    get:
      operationId: index
      summary: 'List polls <Badge intent="info" minimal outlined>OAuth Scope: polls:read</Badge>'
      description: Retrieve all polls belonging to a specific publication. Poll choices are always included. Use `expand[]=stats` to include aggregate vote counts per choice.
      tags:
      - subpackage_polls
      parameters:
      - name: publicationId
        in: path
        description: The prefixed ID of the publication object
        required: true
        schema:
          $ref: '#/components/schemas/type_ids:PublicationId'
      - name: limit
        in: query
        description: A limit on the number of objects to be returned. The limit can range between 1 and 100, and the default is 10.
        required: false
        schema:
          type: integer
      - name: cursor
        in: query
        description: '**Cursor-based pagination (recommended)**: Use this opaque cursor token to fetch the next page of results. When provided, pagination will use cursor-based method which is more efficient and consistent than offset-based pagination.'
        required: false
        schema:
          type: string
      - name: page
        in: query
        description: '**Offset-based pagination (deprecated)**: Page number for offset-based pagination. Please migrate to cursor-based pagination using the `cursor` parameter. If not specified, results 1-10 from page 1 will be returned.'
        required: false
        schema:
          type: integer
      - name: order_by
        in: query
        description: The field that the results are sorted by. Defaults to created.<br> `created` - The time the poll was created.<br> `name` - The name of the poll.
        required: false
        schema:
          $ref: '#/components/schemas/type_polls:PollOrderBy'
      - name: direction
        in: query
        description: The direction that the results are sorted in. Defaults to asc.<br> `asc` - Ascending, sorts from smallest to largest.<br> `desc` - Descending, sorts from largest to smallest.
        required: false
        schema:
          $ref: '#/components/schemas/type_:RequestDirection'
      - name: expand[]
        in: query
        description: Optionally expand the response to include additional data.<br> `stats` - Returns aggregate vote counts per choice and total completions.<br> `poll_responses` - Returns up to 10 most recent subscriber responses. Use /polls/{pollId}/responses for paginated access to all responses.<br> `trivia_answer` - Returns the correct answer for trivia-type polls.
        required: false
        schema:
          type: array
          items:
            $ref: '#/components/schemas/type_polls:PollsExpandItems'
      - name: post_id
        in: query
        description: Filter to only return polls that were embedded in the specified post. Accepts a prefixed post ID (e.g. `post_abc123`).
        required: false
        schema:
          type: string
      - name: Authorization
        in: header
        description: Bearer authentication
        required: true
        schema:
          type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_polls:PollsListResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
        '404':
          description: Resource Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
        '429':
          description: Rate Limit Exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
  /publications/{publicationId}/polls/{pollId}:
    get:
      operationId: show
      summary: 'Get poll <Badge intent="info" minimal outlined>OAuth Scope: polls:read</Badge>'
      description: Retrieve detailed information about a specific poll belonging to a publication. Use `expand[]=stats` for aggregate vote counts, or `expand[]=poll_responses` for individual subscriber responses.
      tags:
      - subpackage_polls
      parameters:
      - name: publicationId
        in: path
        description: The prefixed ID of the publication object
        required: true
        schema:
          $ref: '#/components/schemas/type_ids:PublicationId'
      - name: pollId
        in: path
        description: The prefixed ID of the poll object
        required: true
        schema:
          $ref: '#/components/schemas/type_ids:PollId'
      - name: expand[]
        in: query
        description: Optionally expand the response to include additional data.<br> `stats` - Returns aggregate vote counts per choice and total completions.<br> `poll_responses` - Returns up to 10 most recent subscriber responses. Use /polls/{pollId}/responses for paginated access to all responses.<br> `trivia_answer` - Returns the correct answer for trivia-type polls.
        required: false
        schema:
          type: array
          items:
            $ref: '#/components/schemas/type_polls:PollsExpandItems'
      - name: Authorization
        in: header
        description: Bearer authentication
        required: true
        schema:
          type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_polls:PollShowResponse'
        '404':
          description: Resource Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
        '429':
          description: Rate Limit Exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
  /publications/{publicationId}/polls/{pollId}/responses:
    get:
      operationId: list-responses
      summary: 'List poll responses <Badge intent="info" minimal outlined>OAuth Scope: polls:read</Badge>'
      description: Retrieve all individual subscriber responses for a specific poll with cursor-based pagination. Use this endpoint for large datasets instead of the `expand[]=poll_responses` parameter on the poll show endpoint.
      tags:
      - subpackage_polls
      parameters:
      - name: publicationId
        in: path
        description: The prefixed ID of the publication object
        required: true
        schema:
          $ref: '#/components/schemas/type_ids:PublicationId'
      - name: pollId
        in: path
        description: The prefixed ID of the poll object
        required: true
        schema:
          $ref: '#/components/schemas/type_ids:PollId'
      - name: limit
        in: query
        description: A limit on the number of objects to be returned. The limit can range between 1 and 100, and the default is 10.
        required: false
        schema:
          type: integer
      - name: cursor
        in: query
        description: '**Cursor-based pagination (recommended)**: Use this opaque cursor token to fetch the next page of results.'
        required: false
        schema:
          type: string
      - name: page
        in: query
        description: '**Offset-based pagination (deprecated)**: Page number for offset-based pagination.'
        required: false
        schema:
          type: integer
      - name: order_by
        in: query
        description: The field that the results are sorted by. Defaults to created.
        required: false
        schema:
          $ref: '#/components/schemas/type_polls:PollResponsesOrderBy'
      - name: direction
        in: query
        description: The direction that the results are sorted in. Defaults to asc.<br> `asc` - Ascending, sorts from smallest to largest.<br> `desc` - Descending, sorts from largest to smallest.
        required: false
        schema:
          $ref: '#/components/schemas/type_:RequestDirection'
      - name: expand[]
        in: query
        description: Optionally expand the response to include additional data.<br> `post` - Returns the post title and publication date for the post where each response was collected.
        required: false
        schema:
          type: array
          items:
            $ref: '#/components/schemas/type_polls:PollResponsesExpandItems'
      - name: post_id
        in: query
        description: Filter to only return responses collected via the specified post. Accepts a prefixed post ID (e.g. `post_abc123`).
        required: false
        schema:
          type: string
      - name: Authorization
        in: header
        description: Bearer authentication
        required: true
        schema:
          type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_polls:PollResponsesListResponse'
        '404':
          description: Resource Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
        '429':
          description: Rate Limit Exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/type_:Error'
components:
  schemas:
    type_polls:PollOrderBy:
      type: string
      enum:
      - created
      - name
      default: created
      title: PollOrderBy
    type_polls:PollStats:
      type: object
      properties:
        completions:
          type: integer
          description: The total number of responses to this poll.
        vote_counts:
          type: object
          additionalProperties:
            type: integer
          description: A map of poll choice labels to the number of votes each choice received.
      required:
      - completions
      - vote_counts
      title: PollStats
    type_:RequestDirection:
      type: string
      enum:
      - asc
      - desc
      default: asc
      description: The direction of the request. Defaults to `asc`.
      title: RequestDirection
    type_ids:PollId:
      type: string
      description: The prefixed ID of the poll.
      title: PollId
    type_polls:PollsListResponse:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/type_polls:Poll'
          description: An array of polls.
        limit:
          type: integer
          description: The limit placed on the results. If no limit was specified in the request, this defaults to 10.
        page:
          type: integer
          default: 1
          description: '**Offset pagination only**: The page number the results are from. Only present when using deprecated offset-based pagination.'
        total_pages:
          type: integer
          description: '**Offset pagination only**: The total number of pages. Only present when using deprecated offset-based pagination.'
        has_more:
          type: boolean
          description: '**Cursor pagination only**: Indicates whether there are more results available after the current page. Only present when using cursor-based pagination.'
        next_cursor:
          type: string
          description: '**Cursor pagination only**: The cursor token to use for fetching the next page of results. This will be null if has_more is false. Only present when using cursor-based pagination.'
        total_results:
          type: integer
          description: The total number of results from all pages.
      required:
      - data
      title: PollsListResponse
    type_polls:PollResponsesListResponse:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/type_polls:PollResponseItem'
          description: An array of poll responses.
        limit:
          type: integer
          description: The limit placed on the results. If no limit was specified in the request, this defaults to 10.
        page:
          type: integer
          default: 1
          description: '**Offset pagination only**: The page number the results are from. Only present when using deprecated offset-based pagination.'
        total_pages:
          type: integer
          description: '**Offset pagination only**: The total number of pages. Only present when using deprecated offset-based pagination.'
        has_more:
          type: boolean
          description: '**Cursor pagination only**: Indicates whether there are more results available after the current page.'
        next_cursor:
          type: string
          description: '**Cursor pagination only**: The cursor token to use for fetching the next page of results.'
        total_results:
          type: integer
          description: The total number of results from all pages.
      required:
      - data
      title: PollResponsesListResponse
    type_polls:PollsExpandItems:
      type: string
      enum:
      - stats
      - poll_responses
      - trivia_answer
      title: PollsExpandItems
    type_:ErrorDetail:
      type: object
      properties:
        message:
          type: string
        code:
          type: string
      required:
      - message
      - code
      title: ErrorDetail
    type_polls:PollResponsesExpandItems:
      type: string
      enum:
      - post
      title: PollResponsesExpandItems
    type_ids:PublicationId:
      type: string
      description: The prefixed ID of the publication.
      title: PublicationId
    type_polls:Poll:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/type_ids:PollId'
          description: The prefixed ID of the poll.
        name:
          type: string
          description: The name of the poll.
        question:
          type: string
          description: The poll question text.
        description:
          type: string
          description: An optional description of the poll.
        poll_type:
          $ref: '#/components/schemas/type_polls:PollType'
          description: The type of poll.
        status:
          $ref: '#/components/schemas/type_polls:PollStatus'
          description: The current status of the poll.
        created_at:
          type: integer
          description: The time the poll was created. Measured in seconds since the Unix epoch.
        poll_choices:
          type: array
          items:
            $ref: '#/components/schemas/type_polls:PollChoice'
          description: The available choices for this poll.
        trivia_answer:
          type: string
          description: The correct answer for trivia-type polls. Only included when `expand[]=trivia_answer` is specified and the poll is of type trivia.
        stats:
          $ref: '#/components/schemas/type_polls:PollStats'
          description: Aggregate statistics for the poll. Only included when `expand[]=stats` is specified.
        total_responses:
          type: integer
          description: Total number of responses to this poll. Only included when `expand[]=poll_responses` is specified.
        poll_responses:
          type: array
          items:
            $ref: '#/components/schemas/type_polls:PollResponseItem'
          description: Up to 10 most recent subscriber responses. Only included when `expand[]=poll_responses` is specified. Use /polls/{pollId}/responses for paginated access to all responses.
      required:
      - id
      - name
      - question
      - poll_type
      - status
      - created_at
      - poll_choices
      title: Poll
    type_polls:PollResponseItem:
      type: object
      properties:
        id:
          type: string
          description: The unique identifier of the poll response.
        subscription_id:
          $ref: '#/components/schemas/type_ids:SubscriptionId'
          description: The prefixed ID of the subscription that responded.
        poll_choice_id:
          type: string
          description: The UUID of the poll choice selected.
        poll_choice_label:
          type: string
          description: The text label of the poll choice selected.
        created_at:
          type: integer
          description: The time the response was created. Measured in seconds since the Unix epoch.
        extended_feedback:
          type: string
          description: Optional extended feedback provided by the subscriber.
        post_id:
          type: string
          description: The prefixed ID of the post where the response was collected. Only included when `expand[]=post` is specified.
        post_title:
          type: string
          description: The title of the post where the response was collected. Only included when `expand[]=post` is specified.
        post_publish_date:
          type: integer
          description: The scheduled publication date of the post where the response was collected. Measured in seconds since the Unix epoch. Only included when `expand[]=post` is specified. Null if the post is not yet scheduled.
      required:
      - id
      - subscription_id
      - poll_choice_id
      - created_at
      title: PollResponseItem
    type_ids:SubscriptionId:
      type: string
      description: The prefixed ID of the subscription.
      title: SubscriptionId
    type_polls:PollResponsesOrderBy:
      type: string
      enum:
      - created
      default: created
      title: PollResponsesOrderBy
    type_:Error:
      type: object
      properties:
        status:
          type: integer
        statusText:
          type: string
        errors:
          type: array
          items:
            $ref: '#/components/schemas/type_:ErrorDetail'
      required:
      - status
      - statusText
      - errors
      description: The top level error response.
      title: Error
    type_polls:PollStatus:
      type: string
      enum:
      - draft
      - published
      title: PollStatus
    type_polls:PollChoice:
      type: object
      properties:
        id:
          type: string
          description: The unique identifier of the poll choice.
        label:
          type: string
          description: The text label for this choice.
      required:
      - id
      - label
      title: PollChoice
    type_polls:PollType:
      type: string
      enum:
      - voting
      - trivia
      title: PollType
    type_polls:PollShowResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/type_polls:Poll'
      required:
      - data
      title: PollShowResponse
  securitySchemes:
    BearerAuthScheme:
      type: http
      scheme: bearer