Voting operations
Voting operations are responsible for communicating with Voting API.
The namespace is of course called voting. All methods return promises. The general design of the namespace follows this pattern unless stated otherwise:
General call:
sdk.voting .someMethod() .then((response) => { // Handle response }) .catch((error) => { // Handle error });
The responses are comprised of different objects you can find here.
Polls related operations
Get polls
Method: getPolls(filters?, disableCache?)
Method returns list of Polls.
No authentication required.
The response from API is cached for 1 hour. With disableCache
argument you can avoid cached response.
Filters object:
- status:
string
. Options include: "ACTIVE" and "INACTIVE" - flags:
array
. A list of flags who are set to the polls. - limit:
number
. How many polls will be returned in list. - startAfter:
string
. The ID after which the polls should be listed. To be used in the context of infinite scroll/pagination. - entityIds:
string[]
. A list of entity ids who are set in Polls context. - entityType:
string
. The entity type can be 'competition', 'team' or 'player'. - minVotes:
number
. The minimum number of votes that the poll has. - sortOrder:
string
. The result can be sort by created at field in ascending and descending order. Accepted values are:- asc
- desc
Important notes:
entityType
is required when entityIds
filter is provided and in SDK configuration the idSchema is different than native. This is because JS SDK needs to know what type the entity ids are to be able to remap them internally.
If no value is provided for filters, then no filters will be aplied.
Example call:
sdk.voting .getPolls() .then((response) => { // Handle response }) .catch((error) => { // Handle error }); const filters = { limit: 1, startAfter: "5nhifBwMffT8QOkG6jKBM1", flags: ["poll"], status: "ACTIVE", sortOrder: "asc" }; sdk.voting .getPolls(filters) .then((response) => { // Handle response }) .catch((error) => { // Handle error });
Example result
{
meta: {
pagination: {
nextPageStartsAfter: null,
itemsPerPage: 1
}
},
data: [
{
id: "CkuDxfuv3YUJlcGWbZR0",
title: "Premier League knowledge!",
description: "Who holds the record for most goals in Premier League?",
type: "Premier League",
images: {
main: "",
cover: "",
mobile: ""
},
status: "ACTIVE",
totalVotes: 2,
flags: [
"poll"
],
customFields: {
custom: "field"
},
labels: {
new: "label"
},
adContent: "Ad conent",
context: {
content: {
id: "",
label: "",
type: ""
},
tags: [
{
id: "fb:c:3",
type: "competition",
source: "football"
}
],
campaign: {
id: "",
label: ""
}
},
options: [
{
id: "6nHCuOipXJXoO5PJRsjE3b",
title: "Harry Kane",
description: "Some description",
images: {
main: "",
cover: "",
mobile: ""
},
votes: 0
},
{
id: "453hwHfkpB2OokFQonnYSt",
title: "Alan Shearer",
description: "Some description",
images: {
main: "",
cover: "",
mobile: ""
},
votes: 2
}
],
branding: BrandingModel,
embedCode: null,
createdAt: "2024-05-14T14:41:46.012",
updatedAt: "2024-05-14T14:46:28.075"
}
]
}
Get poll by ID
Method: getPollById(pollId, disableCache?)
Method returns poll by ID.
No authentication required.
The response from API is cached for 1 hour. With disableCache
argument you can avoid cached response.
Example call:
sdk.voting .getPollById("CkuDxfuv3YUJlcGWbZR0") .then((response) => { // Handle response }) .catch((error) => { // Handle error });
Example result
{
id: "CkuDxfuv3YUJlcGWbZR0",
title: "Premier League knowledge!",
description: "Who holds the record for most goals in Premier League?",
type: null,
images: null,
status: "ACTIVE",
totalVotes: 2,
flags: [
"poll"
],
customFields: null,
labels: null,
adContent: "Ad conent",
rules: "Some rules",
context: {
content: null,
tags: [],
campaign: null
},
options: [
{
id: "6nHCuOipXJXoO5PJRsjE3b",
title: "Harry Kane",
description: null,
images: null,
votes: 0
},
{
id: "453hwHfkpB2OokFQonnYSt",
title: "Alan Shearer",
description: null,
images: null,
votes: 2
}
],
branding: BrandingModel,
embedCode: null,
createdAt: "2024-05-14T14:41:46.012",
updatedAt: "2024-05-14T14:46:28.075"
}
Vote in Poll
Method: voteForPoll(pollId, optionId)
Method creates a user vote for specific poll.
Authentication required.
Example call:
sdk.voting .voteForPoll("CkuDxfuv3YUJlcGWbZR0", "6nHCuOipXJXoO5PJRsjE3b") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
id: "453hwHfkpB2OokFQonnYSt",
pollId: "CkuDxfuv3YUJlcGWbZR0",
optionId: "6nHCuOipXJXoO5PJRsjE3b",
userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
}
Delete vote in Poll
Method: deleteVoteForPoll(pollId)
Method deletes a user vote for specific poll.
Authentication required.
Example call:
sdk.voting .deleteVoteForPoll("CkuDxfuv3YUJlcGWbZR0") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
true
Get user own vote for single poll
Method: getMyPollVote(pollId, showModels?)
Method returns user's own vote for specific poll.
Authentication required.
When showModels is set to true
, then the response will contain models for poll and option.
Example call:
sdk.voting .getMyPollVote("CkuDxfuv3YUJlcGWbZR0") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
id: "u6h0rEbRFIcoNnkBkycs",
pollId: "CkuDxfuv3YUJlcGWbZR0",
optionId: "6nHCuOipXJXoO5PJRsjE3b",
userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
pollModel: PollBasicModel, // null when showModels is false
optionModel: PollOptionModel //null when showModels is false
}
Get user own votes for polls
Method: getMyPollsVotes(filters?)
Method returns user's own votes for polls.
Filters object:
- limit:
number
. How many votes for polls will be returned in list. - startAfter:
string
. The ID after which the votes for polls should be listed. To be used in the context of infinite scroll/pagination.
Authentication required.
Example call:
sdk.voting .getMyPollsVotes("CkuDxfuv3YUJlcGWbZR0") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
meta: {
pagination: {
nextPageStartsAfter: null,
itemsPerPage: 1
}
},
data: [
{
id: "u6h0rEbRFIcoNnkBkycs",
pollId: "CkuDxfuv3YUJlcGWbZR0",
optionId: "6nHCuOipXJXoO5PJRsjE3b",
userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
pollModel: PollBasicModel,
optionModel: PollOptionModel
}
]
}
Updated 7 months ago