# Authentication and keys

---

## The Authorization header

Every request (except the public reference document, `GET /openapi.json`) needs your key in the `Authorization` header, as a Bearer token:

```
Authorization: Bearer fr8_live_<keyId>_<secret>
```

**Example:**

```bash
curl https://notification-hub.fr8labs.co/api/v1/crm/counts \
  -H "Authorization: Bearer fr8_live_<keyId>_<secret>"
```

* The word `Bearer` may be in any case (`bearer`, `BEARER`). The key itself is case-sensitive.
* An `X-API-Key` header is **not** accepted. It is answered `401 AUTH_REQUIRED`, with a hint to use the Bearer header.
* A missing key, a malformed key, an unknown key and a wrong secret all get the same answer: `401 AUTH_REQUIRED`.


---

## Never put a key in a URL

A key in a URL ends up in browser history, proxy logs and server logs. The Fr8Labs API refuses it:

* A request with a key anywhere in its URL is refused with `400 AUTH_IN_URL`.
* If that key is a **complete, active key**, it is also **revoked automatically**, at once. Create a new key in the API access tile and update your system.
* A query parameter with a credential-style name (for example `api_key`, `token`, `key`, `access_token`, `auth`) is refused with `400 AUTH_IN_URL` too, whatever its value.

Send the key in the `Authorization` header only.


---

## Key format

```
fr8_<env>_<keyId>_<secret>
```

| Part | What it is |
|------|------------|
| `fr8` | Always `fr8` |
| `<env>` | `live` (your real data) or `test` (the shared Fr8Labs sandbox company: see [The test environment](https://docs.fr8labs.co/doc/getting-started-with-the-fr8labs-api-CtcN5guCvJ#the-test-environment)) |
| `<keyId>` | 12 lowercase hex characters. Not secret: it identifies the key in the tile |
| `<secret>` | 43 letters and digits. This is the password |

* The key is shown **once**, when it is created or rotated. Fr8Labs stores only a one-way hash of it and cannot show it again.
* `fr8_live_<keyId>` (the key prefix) is safe to log and to show. Never log the secret.


---

## Keys act as your company's API user

A key never acts as the person who created it. Every key acts as your company's dedicated **API user**, which Fr8Labs sets up when you turn the API on.

* Everything a key does is recorded against the API user.
* A key works on **your company's data only**. You never send a company id: the key decides the company. A request that carries `company_id`, `tenant_id`, `companyId` or `tenantId` (in any case, with `_`, `-` or nothing between the words, at any depth of the body or query) is refused with `400 TENANT_FIELD_FORBIDDEN`, and `details` names where it was found.

> **Note**: Accounting calls take a `company` field. That is different: it is the **name** of one of your own legal entities, as it appears in your accounting system (one of the companies you picked when you turned Accounting on). It is allowed, and every accounting call needs it.


---

## Scopes

A key carries a list of scopes, chosen when it is created. Each operation needs one or more scopes.

| Scope | Module | What it allows |
|-------|--------|----------------|
| `crm:read` | CRM    | Read leads, deals, organizations, contacts, attachment details, counts, forms; search |
| `crm:write` | CRM    | Add and edit contacts, leads, deals, notes and tasks; set status and owner |
| `actions:read` | Freight operations | Read quotations, jobs, costing, job documents' details, invoices, tasks, vendor rate sheets, quotation templates |
| `actions:write` | Freight operations | Create and change quotations, jobs, house and master bills, job invoice drafts |
| `margin` | Freight operations | Buy-side data. Only works together with `actions:read` |
| `accounting:read` | Accounting | Read your ledger for the companies you picked |
| `accounting:write` | Accounting | Create non-job ledger drafts and post drafts the API created |

`GET /me` and `GET /operations/{id}` need no scope.

### The `margin` scope

Freight data has a buy side: what you pay vendors. Without `margin`, a key never sees it.

* On a quotation, buy amounts, profit, markup and the vendor of each rate option are returned **only** to a key with `margin`. Without it, these fields are **absent** from the response (not `null`).
* On vendor rate sheets (`GET /living-rates`), the vendor is returned, and can be used as a filter, only with `margin`.
* Creating a purchase invoice draft from a job's costing (`POST /jobs/{id}/invoices/purchase/convert-costing`) needs `margin` as well as `actions:write`.
* `margin` without `actions:read` does nothing.

Give `margin` only to systems that need to see costs.

### Scopes and modules work together

What a key can do right now is its own scopes **narrowed to what your company has on today**. `GET /me` shows both: `keyScopes` (what the key was created with) and `scopes` (what it can do now).

This tells you which of two errors you will get:

| Error | Meaning | What to do |
|-------|---------|------------|
| `403 SCOPE_DENIED` | The key was not created with the scope this request needs | Create a key with that scope |
| `403 GRANT_REQUIRED` | The key has the scope, but your company's API user does not hold that access right now (for example, the module was turned off) | Ask your company administrator to turn the module back on, or to restore the API user's access |


---

## Key limits

* **Active keys:** your company can hold up to **5** active keys at a time by default. Creating one more is refused with `KEY_CAP_REACHED`. Revoke a key you no longer use, or ask Fr8Labs to raise the limit (up to 20).
* **Rotating at the limit:** a rotation with an overlap counts the old key until it expires, so at the limit it is refused. Rotate with an overlap of 0 instead.
* **Rate limit:** every new key allows **60 requests a minute**. Higher limits (300 or 1,000 a minute) are set by Fr8Labs on request. See [Limits and errors](https://docs.fr8labs.co/doc/limits-and-errors-eC7kUPLFVj).
* **Expiry:** a key does not expire on its own. It stops working when you revoke it, or when the overlap after a rotation ends (`KEY_EXPIRED`). The overlap is 0 to 1,440 minutes; the default is 0, which ends the old key at once. Fr8Labs also revokes a key if the full key is ever sent in a request URL, or if your company's API user is turned off.


---

## When access is switched off

| What happened | What your keys get | What to do |
|---------------|--------------------|------------|
| A **module** was turned off in the API access tile | That module's operations answer `403 GRANT_REQUIRED`, at once, for every key. Other modules keep working | Turn the module back on. Keys need no change |
| Your company administrator narrowed the API user's access in Team Access | The affected operations answer `403 GRANT_REQUIRED` | Ask your company administrator |
| Fr8Labs switched the **API off** for your company | Every request answers `403 API_DISABLED`. Your keys are **not** revoked | Contact Fr8Labs. When the API is switched back on, the same keys work again |
| The **API user** is no longer available | Every request answers `403 API_USER_UNAVAILABLE` | Contact Fr8Labs |
| The key was revoked | `401 KEY_REVOKED`  | Create a new key |
| The overlap after a rotation ended | `401 KEY_EXPIRED`  | Use the replacement key |

While the API is switched off, you can still open the API access tile to see your keys and revoke them. You cannot create, rotate or try keys until it is switched back on.


---

## Keeping keys safe


1. **One key per system**, labelled with the system's name, so you can revoke one without touching the others.
2. **Least privilege.** Give each key only the scopes it needs. Keep `margin` and write scopes for the systems that need them.
3. **Store keys in a secret manager**, never in source control or front-end code.
4. **Rotate regularly**, using an overlap so your system never goes down.
5. **Revoke at once** if a key may have leaked.


---

Documentation owner: Fr8Labs Customer Success. Text reviewed: 18 October 2026.