TotalPoll
REST API
Extension for TotalPoll
Description
Explore and interact with your polls through a RESTful API. This add-on allows you to get the poll object and cast votes by sending HTTP requests to TotalPoll.
Endpoints
Your endpoints will differ based on your permalink settings. You can refer to your poll edit page > Integration > REST API for the relevant URLs for your website settings.
GET /totalpoll/v4/poll/{poll_id}
Get the poll object message including settings, questions, and choices. Example response:
{ "code": 200, "message": "", "data": { "poll": { "id": 6, "title": "My test poll", "permalink": "http:\/\/localhost:8080\/?post_type=poll&p=6", "questions": { "71ad8c53-56ff-4e8e-962b-1d003a3ed504": { "uid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "content": "What is your favorite color?", "settings": { "selection": { "minimum": 1, "maximum": 1 } }, "choices": { "8788643e-925c-4689-a89b-8837fb2da001": { "uid": "8788643e-925c-4689-a89b-8837fb2da001", "type": "text", "label": "Green", "votes": 0, "index": 0, "questionUid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "rank": 4 }, "521afc8b-db5c-4f9b-bb38-49a44b32aef2": { "uid": "521afc8b-db5c-4f9b-bb38-49a44b32aef2", "type": "text", "label": "Yellow", "votes": 0, "index": 1, "questionUid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "rank": 3 }, "96e6c5be-b06b-45dd-be9c-d94ec25fee18": { "uid": "96e6c5be-b06b-45dd-be9c-d94ec25fee18", "type": "text", "label": "Red", "votes": 0, "index": 2, "questionUid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "rank": 2 }, "1eeb368f-7f8c-4bfe-b5fb-2fd163eb0d0f": { "uid": "1eeb368f-7f8c-4bfe-b5fb-2fd163eb0d0f", "type": "text", "label": "Blue", "votes": 0, "index": 3, "questionUid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "rank": 1 } }, "index": 0, "votes": 0 }, "e0b01caa-92ce-4e94-9ff6-95dde7065ca7": { "uid": "e0b01caa-92ce-4e94-9ff6-95dde7065ca7", "content": "Your favorite sport?", "settings": { "selection": { "minimum": 1, "maximum": 1 } }, "choices": { "f14eb042-404f-4973-bac8-157d6fd4f080": { "uid": "f14eb042-404f-4973-bac8-157d6fd4f080", "type": "text", "label": "Swimming", "votes": 0, "index": 0, "questionUid": "e0b01caa-92ce-4e94-9ff6-95dde7065ca7", "rank": 3 }, "ae3721f3-c03c-42cb-8b50-83b991d023e7": { "uid": "ae3721f3-c03c-42cb-8b50-83b991d023e7", "type": "text", "label": "Football", "votes": 0, "index": 1, "questionUid": "e0b01caa-92ce-4e94-9ff6-95dde7065ca7", "rank": 2 }, "dc45bf3e-d321-4b98-8394-afb48ca5211b": { "uid": "dc45bf3e-d321-4b98-8394-afb48ca5211b", "type": "text", "label": "Squash", "votes": 0, "index": 2, "questionUid": "e0b01caa-92ce-4e94-9ff6-95dde7065ca7", "rank": 1 } }, "index": 1, "votes": 0 } }, "fields": [], "acceptingVotes": true, "hasVoted": false }, "status": 200 } }
POST /totalpoll/v4/poll/{poll_id}/vote
Casts a vote to one choice. Example request:
{ "totalpoll": { "choices": { "71ad8c53-56ff-4e8e-962b-1d003a3ed504": ["CHOICE_1_UID"], "e0b01caa-92ce-4e94-9ff6-95dde7065ca7": ["CHOICE_1_UID"] } } }
Example response:
{ "code": 200, "message": "Your vote has been casted successfully.", "data": { "poll": { "id": 6, "title": "My test poll", "permalink": "http://mywebsite.com/poll/my-test-poll", "questions": { "71ad8c53-56ff-4e8e-962b-1d003a3ed504": { "uid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "content": "What is your favorite color?", "settings": { "selection": { "minimum": 1, "maximum": 1 } }, "choices": { "8788643e-925c-4689-a89b-8837fb2da001": { "uid": "8788643e-925c-4689-a89b-8837fb2da001", "type": "text", "label": "Green", "votes": 1, "index": 0, "questionUid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "receivedVotes": 1, "rank": 4 }, "521afc8b-db5c-4f9b-bb38-49a44b32aef2": { "uid": "521afc8b-db5c-4f9b-bb38-49a44b32aef2", "type": "text", "label": "Yellow", "votes": 0, "index": 1, "questionUid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "receivedVotes": 0, "rank": 3 }, "96e6c5be-b06b-45dd-be9c-d94ec25fee18": { "uid": "96e6c5be-b06b-45dd-be9c-d94ec25fee18", "type": "text", "label": "Red", "votes": 0, "index": 2, "questionUid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "receivedVotes": 0, "rank": 2 }, "1eeb368f-7f8c-4bfe-b5fb-2fd163eb0d0f": { "uid": "1eeb368f-7f8c-4bfe-b5fb-2fd163eb0d0f", "type": "text", "label": "Blue", "votes": 0, "index": 3, "questionUid": "71ad8c53-56ff-4e8e-962b-1d003a3ed504", "receivedVotes": 0, "rank": 1 } }, "index": 0, "votes": 1, "receivedVotes": 1 }, "e0b01caa-92ce-4e94-9ff6-95dde7065ca7": { "uid": "e0b01caa-92ce-4e94-9ff6-95dde7065ca7", "content": "Your favorite sport?", "settings": { "selection": { "minimum": 1, "maximum": 1 } }, "choices": { "f14eb042-404f-4973-bac8-157d6fd4f080": { "uid": "f14eb042-404f-4973-bac8-157d6fd4f080", "type": "text", "label": "Swimming", "votes": 0, "index": 0, "questionUid": "e0b01caa-92ce-4e94-9ff6-95dde7065ca7", "receivedVotes": 0, "rank": 3 }, "ae3721f3-c03c-42cb-8b50-83b991d023e7": { "uid": "ae3721f3-c03c-42cb-8b50-83b991d023e7", "type": "text", "label": "Football", "votes": 1, "index": 1, "questionUid": "e0b01caa-92ce-4e94-9ff6-95dde7065ca7", "receivedVotes": 1, "rank": 2 }, "dc45bf3e-d321-4b98-8394-afb48ca5211b": { "uid": "dc45bf3e-d321-4b98-8394-afb48ca5211b", "type": "text", "label": "Squash", "votes": 0, "index": 2, "questionUid": "e0b01caa-92ce-4e94-9ff6-95dde7065ca7", "receivedVotes": 0, "rank": 1 } }, "index": 1, "votes": 1, "receivedVotes": 1 } }, "fields": [] }, "status": 200 } }
Changelog
- INFO First release!
Version 1.0.0
2019-02-08Included with:
Get Started
Pro & Business Subscription
WordPress
4.8.x, 4.9.x, 5.0.x
languages
English
Requirements
TotalPoll 4.0+