Retrieve a Poll

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 initialized the SDK and created a poll 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.

Last updated