📊
Pollz
  • Introduction
  • Quickstart
  • Guides
    • Initializing your app
    • Create a Poll
    • Vote for a Poll
    • Retrieve a Poll
    • Manage Poll Options
    • Listen to update
    • Anonymous Poll
  • Components
    • React
    • React Native
    • Embedded
  • API Reference
    • init()
    • pollOptions()
      • addOption()
      • deleteOption()
      • renameOption()
    • anonymous
      • createAnonymousToken()
      • getAnonymousPoll()
      • voteAnonymously()
    • polls
      • create()
      • get()
      • getAll()
      • vote()
      • rename()
      • deleteOne()
      • listen()
    • pollTypes
      • getAll()
  • Tooling
    • Typescript
    • React
      • usePoll()
      • usePolls()
      • usePollz()
      • usePollTypes()
      • useAnonymousPoll()
Powered by GitBook
On this page
  1. API Reference
  2. polls

vote()

vote(...args: VoteInputArgs): Promise<Poll>

Submit a vote for a poll.

Parameters:

  • ...args (VoteInputArgs): An array containing the following information in order:

    • pollTypeId (PollTypes): The type of the poll (SingleChoice or MultipleChoice).

    • pollId (EntryIdType): The ID of the poll for which to submit the vote.

    • optionIds (EntryIdType[]): An array of option IDs representing the user's vote.

    • userId (string): The unique user identifier.

Returns:

  • A Promise resolving to the updated poll object (Poll), including information such as the poll ID, name, creation date, associated poll type, and updated vote counts.

Example:

const voteArgs = [PollTypes.SingleChoice, 1, [1], 'user-123'];

try {
  const updatedPoll = await pollz.polls.vote(...voteArgs);
  console.log('Vote Submitted:', updatedPoll);
} catch (error) {
  console.error('Failed to submit vote:', error.message);
}

The vote method allows users to submit their votes for a specific poll. Provide the poll type (pollTypeId), the poll ID (pollId), an array of option IDs representing the user's vote (optionIds), and the unique user identifier (userId).

The method returns a Promise resolving to the updated poll object (Poll), which includes details such as the poll ID, name, creation date, associated poll type, and updated vote counts for each option.

Note: Ensure that the provided poll type, poll ID, option IDs, and user ID are valid and correspond to an existing poll in the system.

PreviousgetAll()Nextrename()

Last updated 1 year ago