# Authentication

The API uses two static keys sent as HTTP headers. There is no OAuth flow and no token exchange.

```bash
curl "https://api.load-market.com/v1/get-tracking?trackingId=api-7fK2mQ9xLpR4tN8vB1cD" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-api-client-key: YOUR_CLIENT_KEY"
```

| Header | Key | Required |
| --- | --- | --- |
| `x-api-key` | Partner key issued by Load Market (live or test) | On every endpoint except `GET /health` |
| `x-api-client-key` | Organization key from **Settings > API Key** in the Load Market web app | See the table below |

## Which endpoint needs which key

| Endpoint | `x-api-key` | `x-api-client-key` |
| --- | --- | --- |
| `POST /create-tracking` | Required | Recommended (required with a test key) |
| `GET /get-all-tracking-items` | Required | Required |
| `GET /get-tracking`, `PATCH /edit-tracking`, `PATCH /stop-tracking`, `DELETE /delete-tracking`, `GET /get-reports` | Required | Optional |
| `POST /test/simulate` | Required (test key) | Not used |
| `GET /health` | Not used | Not used |

### Create: client key or MC/DOT number

`create-tracking` needs to know which organization the tracking belongs to. Send the organization's
client key in `x-api-client-key`. Without it, the organization is looked up by `mcNum` or `dotNum` in
the request body - unless your partner key is allowlisted for that organization, the request is
refused with `400 CLIENT_KEY_REQUIRED`. New integrations should always send the client key.
[ELD and Hybrid tracking items](/eld-tracking#before-you-start) follow the same rule.

### Who can see a tracking

A tracking is visible to:

- the partner key that created it, or
- any partner key, when the request also carries the client key of the organization that owns the
  tracking. This is how you read tracking items your customer created in the Load Market web app.

A tracking that is not visible to your request is reported exactly like a tracking that does not exist
(`TRACKING_NOT_FOUND` / `REPORTS_NOT_FOUND`).

## Authentication errors

| HTTP | `code` | Cause | Fix |
| --- | --- | --- | --- |
| 401 | `MISSING_API_KEY` | No `x-api-key` header | Send the header |
| 401 | `INVALID_API_KEY` | Unknown or revoked partner key | Check the key. Ask support if it was rotated |
| 400 | `INVALID_CLIENT_KEY` | `x-api-client-key` does not match any organization. Only create-tracking and get-all-tracking-items check it. Other endpoints ignore an unknown client key (and answer `TRACKING_NOT_FOUND` for other organizations' tracking items) | Copy the key again from Settings > API Key |
| 400 | `CLIENT_KEY_REQUIRED` | The endpoint (or your partner key) requires the client key | Send `x-api-client-key` |

All errors share one format - see [Errors](/errors).

## Trying requests in the browser

- **API reference playground**: open **Authorize**, choose `ApiKeyAuth` and enter your key. When an
  endpoint also needs the client key, add an `x-api-client-key` header in the **Headers** section of
  the request - the playground sends one security scheme at a time.
- **[Swagger console](/swagger-console)**: **Authorize** accepts both keys at once.

Use your **test** key there - see [Test mode](/test-mode). Keys typed into the playground stay in your
browser.

## Keep keys secret

- Call the API **from your server only**. Never ship a key in browser JavaScript, a mobile app or a
  public repository - anyone holding the partner key and a client key can create tracking requests
  billed to that organization.
- Keep keys in environment variables or a secret manager, and out of logs.
- The API reflects any browser origin (CORS) so that the documentation playground works. That is not
  an invitation to call it from a browser in production.

## Rotation and revocation

Keys do not expire. To rotate or revoke a key (for example after a leak or when an employee leaves),
email office@load-market.com from a known contact address and include only the **last 4 characters**
of the key. After a rotation the new key works immediately and the old one stops working within about
5 minutes - switch your configuration right away. Tracking items created with the old key stay visible
to the new one.
