> ## Documentation Index
> Fetch the complete documentation index at: https://api.pollunit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create vote

> Casts a vote of a participant for an option. Create the participant first; the participant has to belong to the requesting user — identified by the private token or, for anonymous users, by the X-POLLUNIT-USER-IDENTIFIER header. The poll has to accept votes, and its vote limits and access restrictions apply. For pairwise comparisons `option_id` is the winner and has to be one of the two options the options list currently returns for the participant; the other one is stored as `loser_option_id`. Polls that require a double opt in answer with 422 until the participant confirmed the opt in email; the vote is kept and cast on confirmation.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/polls/{poll_id}/votes
openapi: 3.0.1
info:
  title: PollUnit API
  version: v1
  description: Programmatic access to PollUnit.
servers:
  - url: https://pollunit.com
    description: Production
  - url: http://localhost:3000
    description: Development
security:
  - bearerAuth: []
paths:
  /api/v1/polls/{poll_id}/votes:
    parameters:
      - name: poll_id
        in: path
        description: Poll member_hash or admin_hash
        required: true
        schema:
          type: string
      - name: organization_id
        in: query
        required: false
        description: >-
          public_id of an organization the user belongs to. When given, the
          request runs in that organization context instead of the personal
          account.
        schema:
          type: string
    post:
      tags:
        - Votes
      summary: Create vote
      description: >-
        Casts a vote of a participant for an option. Create the participant
        first; the participant has to belong to the requesting user — identified
        by the private token or, for anonymous users, by the
        X-POLLUNIT-USER-IDENTIFIER header. The poll has to accept votes, and its
        vote limits and access restrictions apply. For pairwise comparisons
        `option_id` is the winner and has to be one of the two options the
        options list currently returns for the participant; the other one is
        stored as `loser_option_id`. Polls that require a double opt in answer
        with 422 until the participant confirmed the opt in email; the vote is
        kept and cast on confirmation.
      parameters:
        - name: X-POLLUNIT-USER-IDENTIFIER
          in: header
          required: false
          description: >-
            Your own identification of the user on whose behalf the request is
            made, any string. The user identifiers should not be guessable and
            stay secret, otherwise users could get access to other users'
            contents. Only used with a public API token: the created or changed
            object belongs to that anonymous user instead of the token owner,
            which keeps the user in control of it in later requests with the
            same identifier.
          schema:
            type: string
        - name: X-POLLUNIT-POLL-PASSWORD
          in: header
          required: false
          description: >-
            Access password of the poll. Only needed for password protected
            polls.
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VoteCreateRequest'
      responses:
        '200':
          description: bought votes have to be paid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VotePayment'
        '201':
          description: vote created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Vote'
        '401':
          description: unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Unauthorized'
        '403':
          description: forbidden (the participant belongs to somebody else)
        '404':
          description: poll, participant or option not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
        '422':
          description: invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
      security:
        - bearerAuth: []
components:
  schemas:
    VoteCreateRequest:
      type: object
      properties:
        voter_id:
          type: string
          description: Voter public_id of the participant who votes
        option_id:
          type: string
          description: Option public_id
        vote:
          allOf:
            - $ref: '#/components/schemas/VoteInput'
            - type: object
              properties:
                voting_category_id:
                  type: integer
                  nullable: true
                  description: >-
                    Required when the poll has `voting_categories`: id of one of
                    them, as listed in the poll show response.
      required:
        - voter_id
        - option_id
        - vote
    VotePayment:
      type: object
      description: >-
        Returned instead of the vote when the poll sells votes
        (`voting_fee_type` `voting_sell_votes`). The vote is saved, but the
        bought votes only count once the payment page has been completed.
      properties:
        message:
          type: string
          example: Complete payment for voter
        url:
          type: string
          format: uri
          description: Payment page for the bought votes.
    Vote:
      type: object
      description: >-
        A vote of one participant for one option. Which value field is set
        depends on the poll's `vote_type`.
      properties:
        id:
          type: string
          description: Vote id
        type:
          type: string
          example: Votes::RatingVote
        created_at:
          type: string
          format: date-time
          nullable: true
        updated_at:
          type: string
          format: date-time
          nullable: true
        option_id:
          type: string
          nullable: true
          description: >-
            Option public_id. For pairwise comparisons the option that won the
            comparison.
        loser_option_id:
          type: string
          nullable: true
          description: >-
            Pairwise comparisons only: option public_id of the option that lost
            the comparison.
        voter_id:
          type: string
          nullable: true
          description: Voter public_id
        vote:
          anyOf:
            - type: number
              nullable: true
            - type: string
              nullable: true
          description: >-
            The value of the vote, whichever of `vote`, `vote_date`, `vote_text`
            or the decimal value is set.
        vote_date:
          type: string
          format: date
          nullable: true
          description: Day the vote was cast on, for polls with `vote_per_day`.
        vote_text:
          type: string
          nullable: true
          description: Value of text votes, e.g. table columns.
        paid:
          type: boolean
          nullable: true
          description: >-
            Admin access only, and only for polls with a voting wallet. `false`
            while bought votes are not paid yet.
        voting_category_id:
          type: integer
          nullable: true
          description: Only for polls with `voting_categories`.
      required:
        - id
        - type
    Unauthorized:
      type: object
      properties:
        error:
          type: string
          example: Unauthorized
    NotFound:
      type: object
      properties:
        error:
          type: string
          example: Not Found
    Errors:
      type: object
      properties:
        error:
          type: string
          example: Unprocessable Entity
        errors:
          type: object
    VoteInput:
      type: object
      properties:
        vote:
          type: integer
          nullable: true
          example: 1
          description: >-
            Numeric value of the vote. Its meaning depends on the poll's
            `vote_type`, e.g. `1` for yes or the number of stars. For polls with
            `voting_fee_type` `voting_sell_votes` it is the number of votes to
            buy.
        vote_text:
          type: string
          nullable: true
          description: Value of text votes, e.g. table columns.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: opaque
      description: Personal API token — find yours under My Account → API.

````