Authentication
Every API request is authenticated with an API key sent in the Authorization header.
Create an API key
Section titled “Create an API key”You need to be an admin in your organization to view, create or revoke API keys. Other members see a message that they need admin access instead of the key list.
- In the Safety Radar dashboard, open Settings.
- Under Account, select API Keys.
- Select New API Key.
- Enter a Name that says what the key is for, for example
HR system sync. - Choose an Expiration: Never (the default), 30 days, 90 days or 1 year. The key stops working at that time.
- Select Create.
- The new key is shown once. Select Copy, store the key in your integration’s secret store, then select Done.
What a key can do
Section titled “What a key can do”- A key has admin access to your organization’s data through the API. Treat it like a password.
- Changes made through the API are attributed to the person who created the key.
- A key works until it is revoked or, if you set an expiration, until it expires. A key set to Never expire works until it is revoked. You can’t change a key’s expiration after you create it; create a new key instead.
- The API Keys page shows, for each key, when it was last used (updated at most once a minute) and when it expires. A key that expires within 7 days is highlighted, and an expired key is marked Expired.
- A key works for one organization only.
- Safety Radar stores only a hash of each key, so nobody can see a key again after it is created. The API Keys page shows the first characters of each key to help you tell them apart. If a key is lost, revoke it and create a new one.
Send the key with each request
Section titled “Send the key with each request”Put the key in the Authorization header with the Bearer scheme:
Authorization: Bearer YOUR_API_KEYThe Bearer scheme is required. The word Bearer is not case-sensitive (bearer works
too), but the header must be exactly the scheme, a space and the key. A key sent on its own,
with another scheme, or with extra text after it is refused with 401.
curl https://safe-api.safetyradar.com/v2/events?limit=10 \ --header "Authorization: Bearer $SAFETY_RADAR_API_KEY"const response = await fetch('https://safe-api.safetyradar.com/v2/events?limit=10', { headers: { Authorization: `Bearer ${process.env.SAFETY_RADAR_API_KEY}` },});const { data } = await response.json();import osimport requests
response = requests.get( "https://safe-api.safetyradar.com/v2/events", params={"limit": 10}, headers={"Authorization": f"Bearer {os.environ['SAFETY_RADAR_API_KEY']}"},)data = response.json()["data"]When authentication fails
Section titled “When authentication fails”A missing, malformed, unknown, revoked or expired key returns 401 Unauthorized:
{ "code": "unauthorized", "message": "Invalid API token"}The message tells you which case it is:
message |
Cause |
|---|---|
Missing authorization header |
No Authorization header was sent. |
Invalid authorization header format. Expected: Bearer <API key> |
The header is not Bearer followed by the key. |
Invalid API token |
The key is unknown or has been revoked. |
API key has expired |
The key’s expiration date has passed. Create a new key. |
Keep keys safe
Section titled “Keep keys safe”- Store keys as secrets. Use your platform’s secret manager or environment variables. Never commit a key to source control or put it in client-side code such as a browser or mobile app.
- Use one key per integration. Name each key after the system that uses it, so you can revoke one integration without breaking the others.
- Rotate keys. To replace a key, create a new one, deploy it to your integration, then
revoke the old one. If a key has an expiration, rotate it before that date: requests with
an expired key fail with
401. - Set an expiration on keys for short-lived or trial integrations, so they stop working on their own.
- Revoke keys you no longer need. On the API Keys page, select Revoke on the key and
confirm. Requests with that key fail with
401straight away. Use the last used time on the API Keys page to spot keys that nothing uses any more. - Review keys when people leave. Changes made with a key are attributed to the person who created it. When that person leaves, replace their keys with ones created by a current admin, and revoke the old keys.
The X-Team header (legacy)
Section titled “The X-Team header (legacy)”Earlier integrations sent an X-Team header to choose a team. The API is now scoped to
the whole organization, so the header is no longer needed and is ignored. Existing
integrations that still send it keep working. New integrations should not send it.

