
# Authentication

Every `/api/v1/` request carries an API key and secret, as two headers:

```bash
api-key: fob_mdm_xxxxxxxxxxxxxxxxxx
api-secret: xxxxxxxxxxxxxxxxxxxxxxxx
```

Not an `Authorization: Bearer` header: two separate headers, both required.

## Example Request

```bash
curl -X GET "https://mdm.finopsbricks.com/api/v1/objects" \
  -H "api-key: $MDM_API_KEY" \
  -H "api-secret: $MDM_API_SECRET"
```

## With the CLI or the client

[`fob-mdm`](/docs/cli) sends these headers for you. It keeps the key and secret in a profile, which you create once with `fob-mdm config profiles add <name>`; it asks for both and checks the key before saving. It doesn't read them from environment variables. The [JavaScript client](/docs/cli/client) takes them as arguments: `fobMdm({ api_key, api_secret })`.

## Creating a key

Create keys under **Settings → API Keys** in your organization. A key belongs to one organization, and every request it makes sees only that organization's objects and records. Ids from another organization answer `404`.

## Permissions

A key has a scope per resource and action. `GET` needs `read`, `POST` needs `create`, `PUT` needs `edit` and `DELETE` needs `delete`.

| Resource | Covers |
|---|---|
| `objects` | [Objects](/docs/api/endpoints/objects) |
| `fields` | [Fields](/docs/api/endpoints/fields) |
| `records` | [Records](/docs/api/endpoints/records): records, their values and history |
| `integrations` | [Integrations](/docs/api/endpoints/integrations): connected apps, pulling their records and the record links |
| `conformance` | [Conformance contracts](/docs/api/endpoints/conformance-contracts), [reconcile, states, enforce and confirm](/docs/api/endpoints/conformance) |
| `tags` | Tags |

Two presets are offered when you create a key:

- **Full Access**: every action on every resource. For importers and agents that write.
- **Read Only**: `read` on every resource. For reporting and review.

Choose **Custom** to tick individual permissions.

## Who made a change

Changes made with a key are recorded with the actor `api_key:<id>`, in a record's [history](/docs/api/endpoints/records/transitions) and in the organization's **Activity** feed, which also shows the key's name.

## Failures

| Status | Code | Meaning |
|---|---|---|
| 401 | `UNAUTHORIZED` | A header is missing, the key or secret is wrong, or the key has expired |
| 403 | `FORBIDDEN` | The key lacks the permission, e.g. `API key lacks records:edit permission` |

See [Errors](/docs/api/errors) for the full list.
