Skip to content

API Keys

An API key lets your code act in Shortn on your behalf. Every request sends one, and the key decides what the request may do and which workspaces it may touch. This page is about using keys well; Profile → API keys shows where to create and manage them, and authentication lists every scope and error.

How a key works

  • A key begins with sk_live_. Send it in the Authorization header: Authorization: Bearer sk_live_... (X-API-Key: sk_live_... works too).
  • It acts as you, never with more than you can do: links limited to teams you aren’t in stay hidden, unless you’re a workspace owner or administrator.
  • Its permissions (scopes) choose which endpoints it may call, and its data access chooses the workspaces: every workspace you belong to, or just one.
  • Shortn keeps only a hash of it. The secret is shown once, when you create the key; a lost key can’t be shown again, only replaced.

Choose the right key

One key per integration. Give your CRM sync, your checkout backend and your reporting script a key each, named after what uses it. You can then revoke one without breaking the others, and Last used in the key list tells you which integrations are still running. You can have up to 25 active keys. They share your plan’s rate limits, so more keys don’t raise them.

Account-wide or one workspace.

  • A workspace key can’t see or change anything in your other workspaces: requests for them answer 403 api_key_workspace_mismatch. Use one when an integration belongs to a single brand or client, for example when an agency connects a client’s store. Its rate limits follow the workspace owner’s plan.
  • An account-wide key works in every workspace you belong to. Use it for tools that span workspaces, and to add, verify or remove custom domains, which only account-wide keys can do.

The narrowest permissions. Turn on only what the integration calls. Read and edit are separate: a key that creates links and lists them needs both links:write and links:read. Some common sets:

IntegrationPermissions
A backend that reports leads and salesconversions:write (the Conversion preset also adds conversions:read)
A dashboard or BI exportlinks:read, analytics:read, conversions:read
A tool that creates links for campaignslinks:write, links:read, tags:read, utm-templates:read
Workspace administrationread and edit for teams, tags, UTM templates, destinations and reports, as needed (teams:read, teams:write and so on)

An expiry for temporary keys. A key for a one-off import, a contractor or a trial ends on its own at the end of the date you set.

An owner who stays. A key belongs to the person who created it and stops working if they leave its workspace. Create keys for long-running integrations from an account that will stay, such as the workspace owner’s.

Keep it secret

A key is a password. Anyone who has it can do what it allows until it is revoked.

  • Keep it on your server. Store it in an environment variable or your platform’s secret manager, and read it at startup. Copy env in the app gives you SHORTN_API_KEY and SHORTN_API_BASE ready to paste.
  • Never ship it to a browser or an app. Anything in frontend JavaScript, a mobile app or a desktop app can be read by its users. The API doesn’t accept keyed requests from web pages on other sites anyway; call it from your backend and pass the results on. (A few public endpoints need no key.)
  • Keep it out of Git, URLs and logs. Don’t commit it, put it in a query string or print it in logs and error reports. If your logging records request headers, mask Authorization.

Rotate without downtime

Replace keys from time to time, and whenever someone who had access leaves. You can hold two keys at once, so nothing has to stop:

  1. Create a new key with the same data access and permissions.
  2. Deploy it to the integration.
  3. Check that Last used of the new key moves and the old one’s stops.
  4. Revoke the old key.

If a key leaks

  1. Revoke it in Profile → API keys. It stops working at once.
  2. Create a replacement and deploy it.
  3. Check what it did: its Last used time, your links, and for conversion keys the event log, which shows each API call with the key that made it.

When a key is refused

AnswerWhat to check
401 api_key_requiredThe request carries no key: check the header name and that the variable is set.
401 invalid_api_keyThe key is wrong, revoked or expired, or its owner left the workspace.
403 api_key_scope_not_allowedThe key lacks a permission; details.required_scope names it.
403 api_key_workspace_mismatchA workspace key asked for something in another workspace.
403 account_scoped_api_key_requiredCustom domains need an account-wide key.

The full list is in authentication errors.

Last updated on