Poll Lifecycle

For an explanation of how to attach polls to other objects, read How To File. Functionally they are almost identical: Create a poll and use the +io.pnut.core.poll replacement raw value on a io.pnut.core.poll-notice raw item.

You may also look at the GitHub object-metadata.

Endpoints:

POST /polls

Token: user

Scope: polls,write_post

Create a poll placeholder or a complete poll. type, prompt, options, and duration or closed_at are necessary. By default, the poll will be private and anonymous.

Content-Type of application/json.

POST Body Data

Name Description
prompt Required 256-character explanation or question for the options (to be displayed and attached to the object)
type Required Reverse domain name-style identifier of the poll type. E.g., com.example.site
options Required List of 2 to 10 options must be specified, each with text and optional position (if you want to specify their order)
closed_at Required (if duration not set) ISO 8601 timestamp at least 1 minute and no more than 2 weeks in the future, after which no one can respond to it
duration Required (if closed_at not set) number of minutes the poll should be open, minimum of 1 and maximum of 20160
is_public If true, poll is public
is_anonymous If false, user IDs will be identified in the final poll
Example
curl "https://api.pnut.io/v0/polls" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -H "Content-Type: application/json" \
    -d "{
  \"type\":\"com.example.site\",
  \"prompt\":\"Do you like Pnut?\",
  \"options\":[
    {
      \"text\":\"Yes\"
    },
    {
      \"text\":\"Of course\"
    }
  ],
  \"duration\":\"60\",
  \"is_anonymous\":\"false\"
}" \
    -X POST \
    -H "X-Pretty-Json: 1"

Returns the created poll

"call for example 1"

PUT /polls/{poll_id}/response/{position}

Token: user

Scope: polls,write_post

Respond to a poll.

Only human-type accounts may respond to polls.

URL Parameters

Name Description
poll_id ID of the poll to respond to
position Position of the position to respond with
Example
curl "https://api.pnut.io/v0/polls/1/response/2" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -X PUT \
    -H "X-Pretty-Json: 1"

Returns poll on success

DELETE /polls/{poll_id}

Token: user

Scope: polls

Delete a poll. This will not disassociate a poll with any other objects (posts, messages...).

URL Parameters

Name Description
poll_id ID of the poll to delete
Example
curl "https://api.pnut.io/v0/polls/72" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -X DELETE \
    -H "X-Pretty-Json: 1"

Returns the deleted poll

"call for example 3"