REST API
WB Polls provides a REST API for managing standalone polls programmatically. Use these endpoints to create, list, manage, and retrieve results for polls from external applications or custom integrations.
Base URL
Section titled “Base URL”All endpoints are under the following namespace:
https://yoursite.com/wp-json/wbpoll/v1/Authentication
Section titled “Authentication”The API uses WordPress REST API authentication. Protected endpoints require one of these methods:
- Cookie Authentication works automatically for logged-in users
- Application Passwords suit external applications connecting to WordPress
- OAuth or JWT can be added via third-party plugins
Include the X-WP-Nonce header with a valid WordPress REST nonce for authenticated requests.
Endpoints
Section titled “Endpoints”List All Polls
Section titled “List All Polls”Retrieve all published polls.
GET /wp-json/wbpoll/v1/listpollAuthentication: Public (returns published polls only)
Response Example:
[ { "id": 140, "title": "What is your favorite programming language?", "content": "Help us understand which languages are most popular.", "date": "2026-01-02 09:58:12", "options": [ { "label": "JavaScript" }, { "label": "Python" }, { "label": "PHP" } ], "start_time": "2026-01-02 09:58:12", "end_date": "2026-01-09 09:58:12", "never_expire": "no", "multivote": "no" }]Get Poll by ID
Section titled “Get Poll by ID”Retrieve a specific poll.
POST /wp-json/wbpoll/v1/listpoll/idAuthentication: Public for published polls, owner or admin for drafts and pending polls
Request Body:
{ "pollid": 140}Get User Polls
Section titled “Get User Polls”Retrieve all polls created by a specific user.
POST /wp-json/wbpoll/v1/listpoll/user/idAuthentication: Required (returns own polls unless admin)
Request Body:
| Parameter | Type | Description |
|---|---|---|
id |
integer | User ID (must match logged-in user unless admin) |
status |
string | Filter by status: any, publish, draft, pending |
Create or Update a Poll
Section titled “Create or Update a Poll”Create a new poll or update an existing one.
POST /wp-json/wbpoll/v1/postpollAuthentication: Required (must have poll creation permission)
Request Body:
| Parameter | Type | Required | Description |
|---|---|---|---|
title |
string | Yes | Poll title or question |
content |
string | No | Poll description |
poll_type |
string | No | Type: default, image, video, audio, html, rating, yesno. Left out on a create, the poll is a text poll (default). On an update, leave it out to keep the current type |
poll_id |
integer | No | Poll ID for updates (omit to create new) |
_wbpoll_answer |
array | Yes | Array of answer option texts: at least 2, all different. Blank answers are dropped, "0" counts as an answer, and answers that differ only in case or spacing count as the same answer. Not needed for rating and yesno polls, which make their own answers. On an update, leave it out to keep the current answers |
_wbpoll_answer_extra |
array | No | Answer types. When sent, one entry of the poll’s type is saved per answer, whatever the list’s length |
_wbpoll_start_date |
string | No | Start date in Y-m-d H:i:s format |
_wbpoll_end_date |
string | No | End date in Y-m-d H:i:s format |
_wbpoll_never_expire |
string | No | Send 1 for a poll that never expires. Other values, including yes, do not stop the end date from closing the poll |
_wbpoll_multivote |
string | No | Send 1 (or yes) for multi-select |
_wbpoll_show_result_before_expire |
string | No | Send 1 to hold results until the poll ends. It has no effect on a poll with no end date or that never expires |
Media Fields by Poll Type:
| Poll Type | Additional Field | Value |
|---|---|---|
image |
_wbpoll_full_size_image_answer |
Array of image URLs |
video |
_wbpoll_video_answer_url |
Array of video URLs |
audio |
_wbpoll_audio_answer_url |
Array of audio URLs |
html |
_wbpoll_html_answer |
Array of HTML strings |
Text Poll Example:
{ "title": "What is your favorite color?", "content": "Help us pick the theme color.", "poll_type": "default", "_wbpoll_answer": ["Red", "Blue", "Green"], "_wbpoll_never_expire": "1"}Image Poll Example:
{ "title": "Choose your workspace", "poll_type": "image", "_wbpoll_answer": ["Minimalist", "Cozy", "Standing Desk"], "_wbpoll_answer_extra": ["image", "image", "image"], "_wbpoll_full_size_image_answer": [ "https://example.com/minimalist.jpg", "https://example.com/cozy.jpg", "https://example.com/standing.jpg" ]}Success Response:
{ "success": true, "message": "Your poll is published.", "post_id": 145, "url": "https://yoursite.com/poll/your-poll-slug/"}Pause a Poll
Section titled “Pause a Poll”Temporarily stop a poll from accepting votes.
POST /wp-json/wbpoll/v1/listpoll/pause/pollAuthentication: Owner or admin
Request Body:
{ "pollid": 140, "_wbpoll_pause_poll": 1}Send _wbpoll_pause_poll as 0, or omit it, to resume the poll.
Delete a Poll
Section titled “Delete a Poll”Permanently delete a poll.
POST /wp-json/wbpoll/v1/listpoll/delete/pollAuthentication: Owner or admin
Request Body:
{ "pollid": 140}Unpublish a Poll
Section titled “Unpublish a Poll”Change a poll’s status from published to draft.
POST /wp-json/wbpoll/v1/listpoll/unpublish/pollAuthentication: Owner or admin
Request Body:
{ "pollid": 140}Publish a Poll
Section titled “Publish a Poll”Change a poll’s status from draft to published.
POST /wp-json/wbpoll/v1/listpoll/publish/pollAuthentication: Owner or admin
Request Body:
{ "pollid": 140}Get Poll Results
Section titled “Get Poll Results”Retrieve detailed voting results for a poll.
POST /wp-json/wbpoll/v1/listpoll/result/pollAuthentication: Owner or admin
Request Body:
{ "pollid": 140}Error Responses
Section titled “Error Responses”All endpoints return errors in the standard WordPress REST API format:
{ "code": "rest_forbidden", "message": "You do not have permission to manage this poll.", "data": { "status": 403 }}Common Error Codes
Section titled “Common Error Codes”| Code | Status | Description |
|---|---|---|
rest_not_logged_in |
401 | User must be logged in |
rest_forbidden |
403 | User lacks permission |
rest_invalid_poll |
400 | Invalid poll ID provided |
rest_poll_not_found |
404 | Poll does not exist |
poll_type_disabled |
403 | Poll type is disabled in settings |
poll_create_failed |
500 | Server error creating poll |
poll_delete_failed |
400 | Failed to delete poll |
Code Examples
Section titled “Code Examples”JavaScript: Fetch All Polls
Section titled “JavaScript: Fetch All Polls”fetch('/wp-json/wbpoll/v1/listpoll') .then(response => response.json()) .then(polls => console.log(polls));JavaScript: Create a Poll
Section titled “JavaScript: Create a Poll”fetch('/wp-json/wbpoll/v1/postpoll', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': wpApiSettings.nonce }, body: JSON.stringify({ title: 'My New Poll', content: 'Description here', poll_type: 'default', '_wbpoll_answer': ['Option 1', 'Option 2', 'Option 3'], '_wbpoll_never_expire': '1' })}).then(response => response.json()).then(result => console.log(result));PHP: Create a Poll
Section titled “PHP: Create a Poll”$response = wp_remote_post( rest_url( 'wbpoll/v1/postpoll' ), array( 'headers' => array( 'X-WP-Nonce' => wp_create_nonce( 'wp_rest' ) ), 'body' => array( 'title' => 'New Poll Question', 'content' => 'Poll description', '_wbpoll_answer' => array( 'Option 1', 'Option 2', 'Option 3' ) ) ));
$data = json_decode( wp_remote_retrieve_body( $response ), true );Rate Limiting
Section titled “Rate Limiting”The poll REST routes do not add rate limiting. The plugin’s public vote and lead-capture handlers limit each visitor to a set number of requests per minute (30 votes), and return a 429 response when the limit is exceeded. Users who can edit posts are not limited. Developers can change the ceiling with the wb_polls_rate_limit_max filter. For other traffic, use a security plugin or server-level limits.

