Page Vote Ajax API

POST /page/{ id }/vote.json

An API allowing you to implement page voting (up or down) for your website's users.

This API affects the upvotes and downvotes properties of the Page object

A user is only permitted to vote once per page, but is also permitted void/undo their vote. Before interacting with this API, within your EVML template, you may wish to determine whether a user has already voted using the userHasVoted(), userHasVotedDown(), and/or  userHasVotedUp() methods of the Page object.

Parameters

dir

The direction of vote may be one of the following values:

  • -1 or down - the user wishes to cast a down vote on the page, typically meaning they found the page was not helpful.
  • 1 or up - the user wishes to cast an up vote on the page, typically meaning they found the page was helpful.
  • 0 or void - the user wishes to void/remove their existing vote.


Response

A successful vote request will return a JSON response with the following properties:

success

A boolean value, true when the vote is successful cast.

upvotes

The total number of upvotes for the page after the vote has been cast.

downvotes

The total number of downvotes for the page after the vote has been case.



Example response


{
    "success": true,
    "upvotes": 1,
    "downvotes": 0
}

Errors

You may encounter the following error status codes when calling this API:

400

A Bad Request response may be encountered when:

  • The page id parameter is missing in the URL path.
  • The dir parameter is missing or invalid.
403

A Forbidden response may be encountered when the user is not recognised.

404

A Not Found response may be encountered when the the page id is invalid.

405

A Method Not Allowed response may be encountered if the vote was not submitted via POST request.

422

An Unprocessable Entity response may be encountered if the vote data code not be saved.