Sign users up
A page or a server reads which lists a site offers, reads where one user stands, and replaces that user’s standing. The three requests below take any one of four credentials, and the credential decides who the request is about.
| Credential | Who the request is about |
|---|---|
| An API key pinned to the site | The userId or email your server sends |
| An EdgeKit session | The signed-in user |
Your own login’s credential, at an external_only site |
The user it resolves to |
| None | Nobody, or the email the request sends |
At an external_only site an EdgeKit session is ignored. A credential that does not verify counts as none: the
request is anonymous, not refused. An API key that does not verify is the one exception, and answers 401. See
Choose who signs users in and
Use your own login.
Every request sends the site in x-edgekit-site-id. A browser request must come from one of the site’s allowed
origins. Nothing here is cached: every answer is Cache-Control: no-store.
A list is named by its id, never by its slug. Take the ids from generated/newsletters.ts or from
GET /v1/newsletters/lists.
Read the site’s lists
Section titled “Read the site’s lists”GET /v1/newsletters/lists answers every deployed list on the site, with its id, slug, label and
description. A disabled list is not in the deployed configuration, so it never appears. A site that has never been
deployed answers an empty list, the same as a site with no newsletters.
Read a user’s standings
Section titled “Read a user’s standings”GET /v1/newsletters/subscriptions answers every deployed list on the site, each with the user’s status. A list
the user has never joined or left is unknown, so one call is enough to render a preference centre.
An anonymous request names nobody, and gets unknown for every list rather than a refusal. A server names the user
with ?userId= under an API key. userId with any other credential is a 400.
curl https://<tenant>.edgekit.ai/v1/newsletters/subscriptions?userId=01999b1e-7a40-7c2d-9e51-2a4c8d0f6b31 \ -H 'x-edgekit-site-id: site_example' \ -H 'Authorization: Bearer <api-key>'{ "subscriptions": [ { "id": "01999b1e-7a40-7c2d-9e51-2a4c8d0f6b31", "slug": "morning_briefing", "label": "The Morning Briefing", "description": "Six stories, every weekday at 06:00.", "status": "subscribed" } ]}Change a user’s standing
Section titled “Change a user’s standing”PUT /v1/newsletters/subscriptions sets the lists the user should end up subscribed to. The body:
| Field | What it does |
|---|---|
subscribed |
Required. The ids of the lists the user should be subscribed to. [] leaves them on none. |
email |
The user’s address, when no credential names a user. An address EdgeKit does not know becomes a new user. |
userId |
The EdgeKit user id. Only with an API key. |
A request names exactly one user. With an API key, send userId or email, never both. With an EdgeKit session or
your own login’s credential, the credential names the user, and sending email or userId as well is a 400.
Anonymously, send email.
It is a full replacement, not a patch. Under a credential that names the user, or an API key, every list on the
site that subscribed leaves out and that the user is on becomes unsubscribed. A page that shows four of five
lists and sends four ids takes the user off the fifth. Three exceptions:
- A list that is
pendingstayspending, named or not. - A
subscribedlist named again stayssubscribed, and no new confirmation is sent. - A list the user has never joined or left stays without a standing when it is left out.
An anonymous request only adds. With nothing but an email, lists the request leaves out are not touched.
Removing a list from someone needs their EdgeKit session, your own login’s credential or your API key. So does
putting back a list the user unsubscribed from: an anonymous request that names it changes nothing, and is answered
as any other.
The answer is every deployed list on the site with its status after the change, so your page sees what the
replacement turned off. It is 202 when any list in it is pending, and 200 otherwise.
For an anonymous request, the answer is built from the request alone and says nothing about the address: the lists
it named read pending or subscribed, and the rest read unknown, whether or not the address belongs to a user
already.
The same body converges on the same standing, so a retry is safe. Each retry sends a fresh confirmation for every
list still pending.
From your server:
curl -X PUT https://<tenant>.edgekit.ai/v1/newsletters/subscriptions \ -H 'x-edgekit-site-id: site_example' \ -H 'Authorization: Bearer <api-key>' \ -H 'content-type: application/json' \ -d '{"email": "ada@example.com", "subscribed": ["01999b1e-7a40-7c2d-9e51-2a4c8d0f6b31"]}'From your page, the browser client’s newsletters calls the same routes on your own domain, under /edgekit/, with
the user’s EdgeKit session if there is one:
import { createClient } from '@edgekitcloud/client-browser';
const client = createClient({ siteId: 'site_example' });
const current = await client.newsletters.subscriptions();
const result = await client.newsletters.replace({ subscribed: ['01999b1e-7a40-7c2d-9e51-2a4c8d0f6b31'], // Only when no one is signed in: email: 'ada@example.com',});
if (result.status === 'ok') { const pending = result.data.subscriptions.filter( (list) => list.status === 'pending', );}client.newsletters throws on 400, 401, 403 and 404, which mean the page is set up wrong, such as list ids
from an outdated generated/newsletters.ts. A 429 comes back as failed, so the form can ask the user to wait. See
createClient.
What a sign-up creates
Section titled “What a sign-up creates”An address EdgeKit has never seen becomes a new user with that email address, unverified. In the same write, the
user is attached to the site, with newsletter as how they arrived, and their standing is written. A request that
only takes lists away attaches nobody, and an unknown address asking to be on no list creates nothing.
Reading the lists or the standings never creates a user. See Users.
Errors
Section titled “Errors”| Status | Code | Cause |
|---|---|---|
400 |
bad_request |
userId without an API key, email beside a credential that names a user, both email and userId, no subscriber, or an address that is not one. |
401 |
unauthorized |
An API key that does not verify. |
403 |
forbidden |
A browser origin the site does not allow, or an API key pinned to another site. |
404 |
not_found |
A list id that is not deployed on this site, or a userId with no user. |
422 |
unprocessable_entity |
A body that does not match the schema, such as one with no subscribed. |
429 |
too_many_requests |
Too many anonymous sign-ups. Comes with Retry-After: 10. |
503 |
service_unavailable |
Anonymous sign-ups are switched off for your organization. Ask EdgeKit. |
A list on another site and a list that does not exist both answer 404, so the API never confirms that a list id
exists elsewhere.
Anonymous sign-ups are limited to about 10 requests every 10 seconds from one IP address on one site. Requests with an EdgeKit session, your own login’s credential or an API key are not limited.
Confirm an address
Section titled “Confirm an address”A site can ask every new address to confirm before any newsletter is sent to it. A standing then starts pending,
and EdgeKit emails a confirmation link for each pending list. The email shows the list’s label and description, and
goes to the address EdgeKit holds for the user, never to one typed into a later request.
- Who confirms. A request under an EdgeKit session subscribes straight away: EdgeKit treats the session as proof
of the address. A request with an API key, your own login’s credential or no credential leaves the standing
pendinguntil the link is clicked. - Turning it on. EdgeKit sets it for your organization, with an override per site, and it reaches requests from the next deploy. It needs mail EdgeKit can send: your own sender, set in Delivery › Configuration › Transactional email, or EdgeKit’s default sender, which is on unless your organization asked for it to be turned off. See Transactional email.
- The link points at
/v1/newsletters/confirmon your tenant host and works for 3 days. Apendingstanding never expires: signing up again sends a fresh link.
GET /v1/newsletters/confirm?token=... shows EdgeKit’s page with a Confirm button and changes nothing, so a mail
scanner that opens the link confirms nobody. The button sends POST /v1/newsletters/confirm with {"token": "..."},
which turns the standing from pending to subscribed and answers the list and confirmed: true. The page needs
JavaScript.
A link used twice answers 200 with confirmed: false, the same as any standing that was no longer pending. An
expired or altered link answers 404 not_found, This confirmation link is not valid.
If the email cannot be sent, the standing stays pending. Signing up again sends another.