Documentation / Integration guide / Part 5 of 18

5. The server check

Call POST /api/v1/access for each view of a metered or paid article. Send the server key as Authorization: Bearer <key>. The body is JSON, a strict object of 4 KiB at most. An unknown field gives 400.

Request fields of the server check
Request fieldTypeRequiredYou send
articlestring, 1 to 200 characters from ! to ~yesThe article reference of part 7.
levelfree, metered or paidyesThe access level of the article.
readerstring, 4,096 characters at mostnoThe value of the reader cookie, when the browser sent one.
meterstring, 4,096 characters at mostnoThe value of the meter cookie, when the browser sent one.
accessKeystring that matches ^[a-z][a-z0-9-]{0,39}$noThe access key of a paid article. No field means paid. Only level: paid takes this field.

The answer is HTTP 200 with JSON. Each field is always present.

Response fields of the server check
Answer fieldTypeYour server does
accessfull, registration_wall or paywallfull: send the paid part with Cache-Control: private, no-store. Each other value: send the teaser and <norspire-wall type="<access>" article="<article>">, and no paid part.
freeLeftinteger or nullA number: render <norspire-meter free-left="<freeLeft>">. null: render no meter element.
knownbooleantrue: add known to <norspire-account>, <norspire-meter> and <norspire-wall>.
setMeterstring or nullA string: set the meter cookie to it for 31 days. null: leave the meter cookie as it is.
clearReaderbooleantrue: delete the reader cookie, and render the page as for a visitor.
tierWallnull, month or yearnull: render the wall of access as before. month or year: add tier-wall="<tierWall>" and access-key="<accessKey>" to <norspire-wall>. For an article with a key, also set access-key when tierWall is null.

known and clearReader are never both true.

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

The access key and the tier wall

A publication can sell more than 1 level of access. A plan has 1 to 10 access keys, for example paid and plus. The admin sets the keys for a new plan. The keys never change after the save. A key is not secret. It can show in access-key on <norspire-wall> and in the public view of the embed. Do not put a secret word in a key.

  1. Save the plan with its keys on the Plans page of the admin before your CMS sends the key. A key that no plan has gives the error unknown_access_key.
  2. Set an access key for each paid article that needs a plan with that key. Send it as accessKey with level: paid.
  3. Send no accessKey for an article that every plan gives. No field means the key paid, and a new plan has the key paid by default.
  4. Do not send accessKey with level: free or level: metered. The answer is 400 invalid_request with the pointer /accessKey and the field code level_not_paid. A value that does not match the format gives the same status, code and pointer.

A subscriber reads a paid article in full only when the plan of the subscription has the key of the article. A subscriber on a plan without that key gets access: paywall and tierWall. The value is the payment period of the plan of the subscriber. Your server then renders <norspire-wall type="paywall" article="<article>" access-key="<accessKey>" tier-wall="<tierWall>">, with the teaser and no paid part. The wall shows the plans that the subscriber can change to.

Meaning of each tierWall value
tierWallThe reader is
nullA visitor, a registered reader, a subscriber with the key, or any reader of an article that is not paid.
monthA subscriber with a month plan that does not have the key.
yearA subscriber with a year plan that does not have the key.

Set access-key="<accessKey>" on the wall of each article sent with accessKey, also when tierWall is null. A visitor then sees only the plans that give the key. With no attribute the wall shows each plan that has the key paid.

A paywall with tierWall set writes no wall view. A 400 unknown_access_key writes no wall view and changes no meter.

The budget

Give each call 1 second in total. In the same call, set a connect timeout of 300 milliseconds when your HTTP client has the option. Keep the connection open between calls. 1 page view makes 1 call at most, with no retry. A call that passes the budget is a call with no answer.

The circuit breaker

Add a circuit breaker to your server. It keeps your pages fast when Norspire is down.

  1. Keep the result of each server check of the last 10 seconds.
  2. With 20 results or more in that window, open the breaker when 50 percent or more are failures. With fewer than 20 results, open it after 5 failures in a row.
  3. Keep it open for the Retry-After value of the last failed answer, from 1 to 30 seconds, when present. Else keep it open for 5 seconds.
  4. While it is open, call no server check. Render <norspire-wall type="unavailable"> at once.
  5. Then let 1 call through. A success closes the breaker and clears the window. A failure opens it again by item 3.

A timeout of the budget, a network error, an answer 429 and an answer 5xx are failures. An answer 400, 401 or 413 is not a failure of the breaker, because a wait does not repair it. The page still shows no paid part. The breaker counts the server checks only.

3 forward rules

  • Ignore each unknown field of an answer. Norspire adds fields in later releases.
  • Keep the reader token as opaque text of 512 characters or fewer. Do not parse it.
  • Use no cookie named ns_entitlement. Norspire reserves the name.

Cookies and HEAD

  • Set the meter cookie when setMeter is a string. Delete the reader cookie when clearReader is true. Part 10 gives the attributes.
  • Do not call the server check for a HEAD request. Answer the headers of the page, with no paid part and no body.
  • Do not call the server check for an article with the access level free. The call answers full and costs a request in the limits of the publication. Send the full text.