Documentation / Integration guide / Part 17 of 18

17. Entitlement read

The entitlement read tells your server the access keys and the subscription state of 1 reader, with 1 call and no view of an article. Use it for the apps of your publisher, for a CRM and to check an event.

These 3 rules hold:

  1. The server check of part 5 decides each view of an article. Do not use the read for that.
  2. The server key stays on your server. An app calls your server, and your server calls the read. Never put the key in an app or in a browser.
  3. The read writes no wall view, changes no meter and opens no site session.

See also the API reference for POST /api/v1/entitlements.

The request

Call POST /api/v1/entitlements with Authorization: Bearer <server key> and a JSON body of 4 KiB at most. The body is a strict object with 1 of these 2 fields. A body with both fields or with no field gives 400 invalid_request.

Request fields of the entitlement read
Request fieldTypeYou send
readerstring, 4,096 characters at mostThe value of the reader cookie of part 4, as your server read it.
readerIdstring, UUIDThe reader ID from data.reader.id in a webhook event or from an earlier answer. A non-UUID string gives 400 invalid_request.

A reader token ends with its site session. After the reader logs out, or after the session ends, the token names no reader, and the read gives known: false. Treat that answer as a visitor. A reader ID does not end with a session.

The answer

The answer is HTTP 200 with JSON, with Cache-Control: private, no-store. Each field is always present. A token or an ID that names no live reader of this publication also gives HTTP 200, with known: false. It is no error.

Response fields of the entitlement read
Answer fieldTypeValue
knownbooleantrue when the request names a live reader of the publication.
readerIdstring, UUID or nullThe reader ID, or null when known is false.
subscriptionobject or nullThe newest subscription of the reader: id, status, plan with id and name, currentPeriodEnd, cancelAtPeriodEnd and endsAt. null for a reader with no subscription.
accessKeysarray of stringsThe access keys that the reader has now. The array is empty for a reader with no access.

Request

curl -sS https://konto.example.no/api/v1/entitlements \
  -H "Authorization: Bearer $SERVER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"readerId": "0193f0b2-1111-7a4e-9d2b-3f6a8c1e2d4f"}'

Response 200

{
  "known": true,
  "readerId": "0193f0b2-1111-7a4e-9d2b-3f6a8c1e2d4f",
  "subscription": {
    "id": "0193f0b2-2222-7a4e-9d2b-3f6a8c1e2d4f",
    "status": "active",
    "plan": { "id": "0193f0b2-3333-7a4e-9d2b-3f6a8c1e2d4f", "name": "Monthly A1" },
    "currentPeriodEnd": "2027-02-10T09:00:00Z",
    "cancelAtPeriodEnd": false,
    "endsAt": null
  },
  "accessKeys": ["paid"]
}

Which status gives keys

  • trialing, active and past_due give the access keys of the plan of the subscription.
  • ended gives an empty list. A subscription that ends at the end of its period is ended from its end date, also before the next background run.
  • A reader with no subscription gives an empty list.

Errors

Each error is application/problem+json, as in part 13. The read has the 9 codes of the table. The causes of part 13 hold, and the wrong-key gate of part 13 counts each 401 after a key lookup.

The 9 error codes of the entitlement read
StatuscodeCause
400invalid_requestThe body has both reader and readerId, or neither. Or readerId is not a UUID, or the body has an unknown field. Fix your server.
401unauthenticatedNo key, a key of the wrong form, an unknown key, a revoked key, or a key of another publication. Replace the key. Do not retry.
401key_mode_mismatchThe key belongs to the other mode. A ns_sk_test_ key fails on production. A ns_sk_live_ key fails on development and sandbox.
403browser_requestThe request came from a browser. Call from your server.
404no_siteThe host has no publication. Check the subscription host.
413too_largeThe body is above 4 KiB.
415unsupported_media_typeThe body is not JSON.
429rate_limitedThe request reached a limit. Wait for the time in Retry-After.
503busyNorspire is busy. Wait for the time in Retry-After, 1 second.

Limits

The entitlement read shares connections and limits with the server check. Those limits include 4 KiB body size, 800 milliseconds server time, the publication gate and the proxy limits. A call to the read takes a place that a server check can use.

  • Call the read when an app starts and after an event, and not for each view of an article.
  • Keep 1 answer for each reader for 1 minute or less, and read it from your own store in between.
  • Limit the path of your app that calls the read, for example to 1 call for each reader in each minute.
  • A 429, a 503, a time-out and a 5xx are failures. Wait for Retry-After. Add a circuit breaker as in part 5 when your server calls the read in a loop.