RenzoDocs

Reactions and views

Like or dislike an article, read the totals, and count a read.

View as Markdown

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

OperationWhat it doesAuth
GET/api/v1/articles/{article_id}/reactionsRead the like and dislike totals. With a token, it also shows your own reaction.Token optional
PUT/api/v1/articles/{article_id}/reactionsLike or dislike: {"kind": "like"} or {"kind": "dislike"}.Token and username
DELETE/api/v1/articles/{article_id}/reactionsRemove your reaction.Token and username
POST/api/v1/articles/{article_id}/viewsReport 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:

Response
{
  "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:

Response
{
  "recorded": true
}

Rules and edge cases

  • Totals. like_count and dislike_count are exact and cover every language of the article. They are never cached.
  • Your reaction. kind is like, dislike or null when you have none. Without a token, kind is always null.
  • 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 200 with the totals.
  • Gating. To react, you must be able to open the article in full. If your plan only gets the preview, PUT and DELETE answer 403 article_access_required. Reading totals has no such check. See Plans and limits.
  • Unpublished articles. A draft, scheduled, archived or unknown ID answers 404 not_found.
  • View body. session_id is any opaque string you make up for the session, 8 to 128 characters. locale is the article locale the reader saw, as the engine code or the public tag. An unsupported locale answers 422 validation_failed.
  • Deduplication. The same session_id on the same article counts once. A repeat answers 202 with recorded: false.
  • No identity. A view is anonymous. Do not send it before the reader has stayed a few seconds.

Errors

CodeStatusWhen
article_access_required403Your plan does not open this article, so you cannot react.
profile_incomplete409The account has no username yet.
not_found404No published article has this ID.

Sign-in and request errors, such as token_expired and validation_failed, can come from any call. See Errors.

Reference

On this page