📊
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

create()

create(input: CreatePollInput): Promise<Poll>

Create a new poll with the specified options.

Parameters:

  • input (CreatePollInput): An object containing the poll creation details.

    • name (string): The name of the new poll.

    • options (string[]): An array of strings representing the poll options.

    • pollTypeId (EntryIdType): The ID representing the type of poll (SingleChoice or MultipleChoice).

Returns:

  • A Promise resolving to the created poll object (Poll).

Example:

const pollInput = {
  name: 'New Poll',
  options: ['Option A', 'Option B', 'Option C'],
  pollTypeId: PollTypes.SingleChoice,
};

try {
  const createdPoll = await pollz.polls.create(pollInput);
  console.log('New Poll Created:', createdPoll);
} catch (error) {
  console.error('Failed to create poll:', error.message);
}

The create method allows you to create a new poll by providing essential details such as the poll name, options, and the type of poll (SingleChoice or MultipleChoice). The method returns a Promise resolving to the created poll object (Poll), which includes details like the poll ID, name, creation date, and associated poll type.

Note: Ensure that the provided pollTypeId corresponds to a valid poll type (SingleChoice or MultipleChoice).

PreviouspollsNextget()

Last updated 1 year ago