Skip to content

Poll

Create and vote on polls.

Endpoints

EndpointArgumentsReturns
poll.createoptions: PollCreateOptionsobject
poll.editpollId: string, pollOptions: PollEditOptionsobject
poll.removepollId: stringboolean
poll.retractretractOptions: { pollId: string, optionId: string }boolean
poll.votevoteOptions: { pollId: string, optionId: string }boolean

poll.create

Description

Creates a poll with given answer visibility and options

Parameters

Argument 1 (object, optional):

FieldTypeRequiredDescription
optionsobject[]yes
answerVisibilitycreator | none | publicyesOne of: creator, none, public.
namestringyes
multipleAnswersbooleanno
draftbooleanno
scheduledbooleanno
scheduleTimenumberno
lockedVotesbooleanno

Example

javascript
const { Client } = require('@hailer/cli');

const client = await Client.create({
  host: 'https://api.hailer.com',
  username: 'you@example.com',
  password: '••••••',
});

const result = await client.request('poll.create', [
  {
    options: [{
      name: 'string',
    }],
    answerVisibility: 'creator',
    name: 'string',
  },
]);
console.log(result);

Returns

FieldTypeRequiredDescription
_idObjectIdyespollId
namestringyes
creatednumberyes
creatorIduserIdyesuserId
optionsRecord<ObjectId, object>yes
answerVisibilitycreator | none | publicyesOne of: creator, none, public.
answersRecord<userId, Record<ObjectId, object>>no
answerCountsRecord<ObjectId, number>no
usersAnsweredCountnumberno
multipleAnswersbooleanno
draftbooleanno
scheduledbooleanno
lockedVotesbooleanno

Auth: requires an authenticated session.

Errors: on failure returns the standard Hailer error object { code, msg, details?, debug? }.

poll.edit

Description

Edits given poll, that is scheduled, to have different visiblity or options

Parameters

Argument 1 (ObjectId, optional): pollId

Argument 2 (object, optional):

FieldTypeRequiredDescription
optionsobject[]no
answerVisibilitycreator | none | publicnoOne of: creator, none, public.
namestringno
multipleAnswersbooleanno
draftbooleanno
scheduledbooleanno
scheduleTimenumberno
lockedVotesbooleanno

Example

javascript
const { Client } = require('@hailer/cli');

const client = await Client.create({
  host: 'https://api.hailer.com',
  username: 'you@example.com',
  password: '••••••',
});

const result = await client.request('poll.edit', [
  '507f1f77bcf86cd799439011', // ObjectId
  {
    options: [{
      name: 'string',
    }],
    answerVisibility: 'creator',
  },
]);
console.log(result);

Returns

FieldTypeRequiredDescription
_idObjectIdyespollId
namestringyes
creatednumberyes
creatorIduserIdyesuserId
optionsRecord<ObjectId, object>yes
answerVisibilitycreator | none | publicyesOne of: creator, none, public.
answersRecord<userId, Record<ObjectId, object>>no
answerCountsRecord<ObjectId, number>no
usersAnsweredCountnumberno
multipleAnswersbooleanno
draftbooleanno
scheduledbooleanno
lockedVotesbooleanno

Auth: requires an authenticated session.

Errors: on failure returns the standard Hailer error object { code, msg, details?, debug? }.

poll.remove

Description

Removes given poll

Parameters

Argument 1 (ObjectId, required): pollId

Example

javascript
const { Client } = require('@hailer/cli');

const client = await Client.create({
  host: 'https://api.hailer.com',
  username: 'you@example.com',
  password: '••••••',
});

const result = await client.request('poll.remove', [
  '507f1f77bcf86cd799439011', // ObjectId (required)
]);
console.log(result);

Returns

boolean

Auth: requires an authenticated session.

Errors: on failure returns the standard Hailer error object { code, msg, details?, debug? }.

poll.retract

Description

Retracts a vote from the given polls option

Parameters

Argument 1 (object, optional):

FieldTypeRequiredDescription
pollIdstringyes
optionIdstringyes

Example

javascript
const { Client } = require('@hailer/cli');

const client = await Client.create({
  host: 'https://api.hailer.com',
  username: 'you@example.com',
  password: '••••••',
});

const result = await client.request('poll.retract', [
  {
    pollId: 'string',
    optionId: 'string',
  },
]);
console.log(result);

Returns

boolean

Auth: requires an authenticated session.

Errors: on failure returns the standard Hailer error object { code, msg, details?, debug? }.

poll.vote

Description

Adds a vote to the given polls option

Parameters

Argument 1 (object, optional):

FieldTypeRequiredDescription
pollIdstringyes
optionIdstringyes

Example

javascript
const { Client } = require('@hailer/cli');

const client = await Client.create({
  host: 'https://api.hailer.com',
  username: 'you@example.com',
  password: '••••••',
});

const result = await client.request('poll.vote', [
  {
    pollId: 'string',
    optionId: 'string',
  },
]);
console.log(result);

Returns

boolean

Auth: requires an authenticated session.

Errors: on failure returns the standard Hailer error object { code, msg, details?, debug? }.

Hailer Developer Documentation