Skip to content
Denne side findes på dansk. Læs på dansk
HeyMySocial

API authentication

How workspace API keys work: where to create one, the hms_live_ format, scopes, expiry and revoking, and what the API answers when a key is refused.

The REST API is opened by a workspace API key. A key is a long random string that starts with hms_live_, belongs to one workspace and carries the scopes you gave it. You send it as a bearer token with every request:

curl https://heymysocial.com/api/v1/content \
  -H "Authorization: Bearer $HMS_API_KEY"

These keys are for the REST API only. An assistant connects with its own sign-in or a personal hms_mcp_ key; see Connect an assistant.

Create a key

  1. Open Settings, API keys in the workspace the key is for. The screen is there for people who may manage integrations in that workspace.
  2. Under Create a key, give it a Name that says where it will be used, for example "Website form".
  3. Tick the Scopes it needs. At least one is required.
  4. Set an Expiry date if the key should stop by itself. It stops working at the end of that day, in the time zone of the workspace. Leave it empty for a key that does not expire.
  5. Press Create key.

The key is then shown under Copy your new key now. This is the only time: only a SHA-256 fingerprint is stored, so nobody, us included, can show it again. Copy it to where your system keeps its secrets, then press I have copied it. If a key is lost, revoke it and create another.

The key format

A key is hms_live_ followed by 40 letters and digits, 49 characters in all.

The list of keys on the screen shows the first 14 characters of each, so you can tell them apart, together with the name, the scopes, when the key was last used and when it expires.

A string that does not start with hms_live_ is refused before anything is looked up.

Scopes

A scope says what a key may do. An operation names the scope it needs, and a key without it is answered 403.

ScopeAllows
events:writeSend events: page views, leads, lead status and sales
leads:readRead leads
leads:writeCreate and update leads
sales:writeRecord sales
content:readRead content
content:writeCreate content drafts
reports:readRead reports
ads:writeImport ad data
Scope Operations it opens
events:write Send events
leads:write Send CRM records in a batch
sales:write Sale records in that batch. It is needed together with leads:write
leads:read List CRM reconciliation errors
content:read List content items, Get one content item
content:write Create a draft, Add a version, Ask a person to approve
ads:write Import ad results
reports:read No operation uses it today

No scope lets a key approve, schedule or publish. There is no such operation.

The key decides the workspace

A request never says which workspace it is for. The workspace is the one the key was created in, and a workspace id in a body or an address is not read.

Everything a key can reach is in that workspace. The id of a content item, a channel or a CRM connection from another workspace is answered 404 not_found, exactly like an id that does not exist.

An agency with several client workspaces creates a key in each one.

Expiry and revoking

  • Expiry. A key with an expiry date is refused from the day after that date.
  • Revoking. Press Revoke next to a key under Keys. Requests with it are refused from then on. A revoked key stays in the list, marked as revoked, and cannot be switched on again.
  • Archived workspaces. The keys of a workspace that is archived stop working until it is restored.

Creating and revoking a key are both written to the workspace's audit log. The key itself is never logged.

When a key is refused

A request without a usable key is answered 401:

{
  "code": "unauthenticated",
  "message": "A valid API key is required (Authorization: Bearer hms_live_...).",
  "request_id": "01M88Q4X0V67X7S6H2DCQJGDB0",
  "retryable": false
}

The answer is the same whether the header is missing, the key is mistyped, revoked or expired, or its workspace is archived. It never says which.

A valid key without the scope an operation needs is answered 403, and the message names the scope:

{
  "code": "access_denied",
  "message": "This API key lacks the scope content:write.",
  "request_id": "01M88Q4X0BKFD50W79NKFXK67W",
  "retryable": false
}

Neither is worth retrying. Fix the key first. Errors describes the shape.

Looking after keys

  • Make one key for each system, and name it after that system. When a system is retired or a key leaks, you revoke one key and nothing else stops.
  • Give each key the fewest scopes that do its job. A website form needs events:write and nothing more.
  • Keep keys on a server: in an environment variable or a secret store. Never put one in a web page, a mobile app or a repository. For a browser there is the tracking script, which uses the public key of a tracking site instead.
  • To replace a key, create the new one, switch your system over, check Last used on the old one, then revoke it.
  • If a key may have been seen by someone else, revoke it at once. It costs one minute to make another.