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 field | Type | Required | You send |
|---|---|---|---|
article | string, 1 to 200 characters from ! to ~ | yes | The article reference of part 7. |
level | free, metered or paid | yes | The access level of the article. |
reader | string, 4,096 characters at most | no | The value of the reader cookie, when the browser sent one. |
meter | string, 4,096 characters at most | no | The value of the meter cookie, when the browser sent one. |
accessKey | string that matches ^[a-z][a-z0-9-]{0,39}$ | no | The 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.
| Answer field | Type | Your server does |
|---|---|---|
access | full, registration_wall or paywall | full: 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. |
freeLeft | integer or null | A number: render <norspire-meter free-left="<freeLeft>">. null: render no meter element. |
known | boolean | true: add known to <norspire-account>, <norspire-meter> and <norspire-wall>. |
setMeter | string or null | A string: set the meter cookie to it for 31 days. null: leave the meter cookie as it is. |
clearReader | boolean | true: delete the reader cookie, and render the page as for a visitor. |
tierWall | null, month or year | null: 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.
- Save the plan with its keys on the
Planspage of the admin before your CMS sends the key. A key that no plan has gives the errorunknown_access_key. - Set an access key for each
paidarticle that needs a plan with that key. Send it asaccessKeywithlevel: paid. - Send no
accessKeyfor an article that every plan gives. No field means the keypaid, and a new plan has the keypaidby default. - Do not send
accessKeywithlevel: freeorlevel: metered. The answer is 400invalid_requestwith the pointer/accessKeyand the field codelevel_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.
tierWall | The reader is |
|---|---|
null | A visitor, a registered reader, a subscriber with the key, or any reader of an article that is not paid. |
month | A subscriber with a month plan that does not have the key. |
year | A 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.
- Keep the result of each server check of the last 10 seconds.
- 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.
- Keep it open for the
Retry-Aftervalue of the last failed answer, from 1 to 30 seconds, when present. Else keep it open for 5 seconds. - While it is open, call no server check. Render
<norspire-wall type="unavailable">at once. - 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
setMeteris a string. Delete the reader cookie whenclearReaderistrue. Part 10 gives the attributes. - Do not call the server check for a
HEADrequest. 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 answersfulland costs a request in the limits of the publication. Send the full text.