Reactions and views
Like or dislike an article, read the totals, and count a read.
Reactions are a like or a dislike on an article. Views count how many readers opened it. Anyone may read reaction totals and report a view. Changing a reaction needs a token and a username.
Endpoints
| Operation | What it does | Auth |
|---|---|---|
GET/ | Read the like and dislike totals. With a token, it also shows your own reaction. | Token optional |
PUT/ | Like or dislike: {"kind": "like"} or {"kind": "dislike"}. | Token and username |
DELETE/ | Remove your reaction. | Token and username |
POST/ | Report one read. Answers 202. | None |
article_id is the article's id, not its slug. Calls that change a reaction need a username on the account. Until one is set, they answer 409 profile_incomplete. See Account. Any mutating call accepts an Idempotency-Key. See Idempotency.
Example: like an article
curl -X PUT "$BASE/api/v1/articles/f43679d3-0ab5-5f68-8bda-f0a4c5560594/reactions" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"kind": "like"}'The answer is 200 with the new totals:
{
"article_id": "f43679d3-0ab5-5f68-8bda-f0a4c5560594",
"kind": "like",
"like_count": 128,
"dislike_count": 7
}Report a read after the reader stays a few seconds. No token is needed:
curl -X POST "$BASE/api/v1/articles/f43679d3-0ab5-5f68-8bda-f0a4c5560594/views" \
-H "Content-Type: application/json" \
-d '{"session_id": "b7e2c9a41f6d4e08", "locale": "en"}'The answer is 202:
{
"recorded": true
}Rules and edge cases
- Totals.
like_countanddislike_countare exact and cover every language of the article. They are never cached. - Your reaction.
kindislike,dislikeornullwhen you have none. Without a token,kindis alwaysnull. - Same reaction twice. It changes nothing and still answers
200. Sending the other kind switches your reaction. - Removing. Removing a reaction that is not there is not an error. It answers
200with the totals. - Gating. To react, you must be able to open the article in full. If your plan only gets the preview,
PUTandDELETEanswer403article_access_required. Reading totals has no such check. See Plans and limits. - Unpublished articles. A draft, scheduled, archived or unknown ID answers
404not_found. - View body.
session_idis any opaque string you make up for the session, 8 to 128 characters.localeis the article locale the reader saw, as the engine code or the public tag. An unsupportedlocaleanswers422validation_failed. - Deduplication. The same
session_idon the same article counts once. A repeat answers202withrecorded: false. - No identity. A view is anonymous. Do not send it before the reader has stayed a few seconds.
Errors
| Code | Status | When |
|---|---|---|
article_access_required | 403 | Your plan does not open this article, so you cannot react. |
profile_incomplete | 409 | The account has no username yet. |
not_found | 404 | No published article has this ID. |
Sign-in and request errors, such as token_expired and validation_failed, can come from any call. See Errors.