Skip to navigation

Authentication

How to prove who you are when you call the Divertly API.
View as Markdown

The API accepts two kinds of credentials, depending on who — or what — is making the request.

CredentialSent asUsed byRate limited?
Session tokenAuthorization: Bearer <token> (or a session cookie)The Divertly dashboard, after you sign inYes, 60 calls per minute
API keyAuthorization: Key <base64(keyId:secret)>Your own code, scripts, and integrationsYes, by plan

A session token is issued when you sign in to the dashboard, and the dashboard manages it for you — you never need to construct one yourself. If you’re calling the API from your own code, use an API key instead. See Rate Limits & Errors for current limits.

Authenticate with an API key

An API key has two parts: a key ID, which identifies the key, and a secret, which proves you hold it. To authenticate a request, join the two with a colon, base64-encode the result, and send it in the Authorization header with the Key scheme:

Authorization: Key <base64("keyId:secret")>

The secret is shown once, at the moment you create the key, and can’t be retrieved afterward. Store it somewhere safe before you close the dialog. If you lose it, delete the key and create a new one.

For instructions on creating and managing keys, see Managing API Keys.

Here’s a complete example. Given a key ID of k_9f2a and a secret of s3cr3t-value:

CREDENTIAL=$(printf '%s' "k_9f2a:s3cr3t-value" | base64)
curl https://api.divert.ly/v1/domains \
-H "Authorization: Key $CREDENTIAL"

Confirm your credential works

Call GET /v1/whoami to resolve a credential to the organization (and, for a session token, the user) it belongs to:

curl https://api.divert.ly/v1/whoami \
-H "Authorization: Key $CREDENTIAL"

An API key resolves to its organization only — there’s no user attached to it, since a key represents an integration rather than a person.

If the credential is missing, malformed, or invalid, every endpoint returns the same error shape, described in Rate Limits & Errors.

Roles

Every API key and user is assigned a role — Super Admin, User, Billing Admin, or Read Only. Roles are enforced for both users and API keys: a request whose role doesn’t permit the action is refused with 403 Forbidden. A key can’t be issued with a role higher than the role of whoever creates it. See Managing Users for the role names, and Managing API Keys for how to assign one when you create a key.

To see which role names your organization can assign, call:

curl https://api.divert.ly/v1/organizations/{org_id}/roles \
-H "Authorization: Key $CREDENTIAL"