# Authentication (/authentication)

Every call needs an API key. A key belongs to one company. Ajour reads the company from the key, so you never send a company id.

## Create a key [#create-a-key]

1. Sign in to the Ajour back office.
2. Go to **Settings → API keys**.
3. Select **Create key**.
4. Enter a name that says who uses the key, for example "Power BI" or "Accounting partner".
5. Choose the [scopes](#scopes) and the [locations](#location-limits).
6. Optional: set an expiry date.
7. Copy the key and keep it in a safe place, such as a password manager.

All users of your company can create, see and revoke your company's keys. Ajour support can also do this for you.

<Callout type="warn" title="The key is shown one time">
Ajour stores only a hash of the key. If you lose the key, revoke it and create a new one.
</Callout>

## Key format [#key-format]

```text
ajr_live_7Kq2Vx9b_Q3n8...
│    │    │        └ secret
│    │    └ key id (shown in the API keys list)
│    └ live
└ prefix
```

The `ajr_` prefix lets secret scanners find a key that was shared by mistake.

## Send the key [#send-the-key]

Send the key in the `Authorization` header as a bearer token:

```sh
curl https://api.ajour.dk/v1/company \
  -H "Authorization: Bearer $AJOUR_API_KEY"
```

The API does not accept keys in the URL, because URLs are saved in logs. A key in the URL returns [`400 key-in-url`](/errors/key-in-url/).

## Scopes [#scopes]

A scope gives the key access to a group of endpoints. Give each key only the scopes it needs.

| Scope | Gives access to |
| --- | --- |
| `catalog:read` | Locations, product groups and products |
| `sales:read` | Sales lines, key figures, breakdowns and salesperson names |
| `reports:read` | Report files (PDF and Excel) |
| `customers:read` | Reports with customer card holders' names, addresses and balances. **Off by default.** |

`GET /v1/company` works with any scope.

If the key does not have the scope that a call needs, the API returns [`403`](/errors/missing-scope/).

## Location limits [#location-limits]

You can limit a key to some of your locations. For example, a chain can give a franchise partner a key that sees only that partner's shop.

- Lists and figures include only the key's locations.
- If you ask for a location outside the key, the API returns [`404`](/errors/not-found/). It does not show that the location exists.
- `GET /v1/company` shows the key's locations in `key.locationIds`. `null` means all locations.

## Revoke a key [#revoke-a-key]

Go to **Settings → API keys** and select **Revoke** next to the key. The key stops working at once. Calls with it return [`401`](/errors/unauthorized/).

The API keys list shows when each key was last used. Revoke keys that nobody uses.

## Keep keys safe [#keep-keys-safe]

- Keep keys on a server or in a password manager. Never put a key in a web page or a mobile app.
- Use one key per system or partner, so you can revoke one without stopping the others.
- Revoke a key at once if you think someone else has it.