📊
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
  • Guide: Retrieving Poll Information with pollz-js SDK
  • Prerequisites
  • Retrieve Poll Information
  1. Guides

Retrieve a Poll

PreviousVote for a PollNextManage Poll Options

Last updated 1 year ago

Guide: Retrieving Poll Information with pollz-js SDK

Prerequisites

Before you proceed with retrieving poll information using the pollz-js SDK, ensure that you have already and by following the relevant guides in the "Guides" section.

Retrieve Poll Information

You can easily retrieve information about a specific poll or a list of all polls using the pollz-js SDK.

Step 1: Import the SDK

In your Node.js application, ensure you have already imported the pollz-js SDK:

const { PollzSDK } = require('pollz-js');

Step 2: Retrieve Information about a Specific Poll

Use the get method provided by the polls module of the SDK to get information about a specific poll. Provide the poll ID as an argument.

const pollz = new PollzSDK();

// Replace 'your-app-id' and 'your-app-secret' with actual credentials
const initInput = {
  appId: 'your-app-id',
  appSecret: 'your-app-secret',
};

// Initialize the SDK
await pollz.init(initInput);

// Replace with the actual poll ID
const pollId = 1;

try {
  const pollInfo = await pollz.polls.get(pollId);
  console.log('Poll Information:', pollInfo);
} catch (error) {
  console.error('Failed to retrieve poll information:', error.message);
}

Replace 'your-app-id' and 'your-app-secret' with the actual credentials obtained from the Pollz platform. Adjust the pollId according to the poll you want to retrieve information about.

Step 3: Retrieve a List of All Polls

Use the getAll method provided by the polls module of the SDK to get a list of all polls.

try {
  const allPolls = await pollz.polls.getAll();
  console.log('All Polls:', allPolls.items);
} catch (error) {
  console.error('Failed to retrieve all polls:', error.message);
}

Congratulations! You have successfully retrieved information about a specific poll and a list of all polls using the pollz-js SDK. Explore more SDK features and functionalities to tailor your application's polling experience. Refer to the relevant guides for detailed instructions on other SDK capabilities.

initialized the SDK
created a poll