# Authentication

How to create a TimeSubmit API key, send it as a bearer token, and choose the scopes it needs, with what each scope allows.

## API keys

A consultancy admin creates a key under Settings, then API & Webhooks, and picks its scopes. The API is on the Core, Margin and Enterprise plans.

The key starts `tsk_` and is shown once, so store it somewhere safe as soon as you create it. It acts for your organisation only: every record it reads or changes is your organisation's, and its changes appear in your audit log under the key's name.

Create one key for each system you connect. You can then revoke one without breaking the others.

## Sending the key

Send the key as a bearer token in the `Authorization` header of every request to `https://www.timesubmit.com/api/v1`:

```bash
curl "https://www.timesubmit.com/api/v1/clients" \
  -H "Authorization: Bearer $TIMESUBMIT_API_KEY"
```

A missing, unknown, revoked or expired key is refused with 401 `unauthorised`. See [errors](https://www.timesubmit.com/developers/errors) for every answer.

## Scopes

A key holds only the scopes it was given, and an operation outside them is refused with 403 `insufficient_scope`. Give each key the fewest scopes its job needs.

| Scope | Allows |
| --- | --- |
| `clients:read` | `GET /clients`, `GET /clients/{id}` |
| `clients:write` | `POST /clients`, `PATCH /clients/{id}`, `POST /clients/{id}/archive` |
| `projects:read` | `GET /projects`, `GET /projects/{id}` |
| `projects:write` | `POST /projects`, `PATCH /projects/{id}` |
| `consultants:read` | `GET /consultants`, `GET /consultants/{id}` |
| `assignments:read` | `GET /assignments`, `GET /assignments/{id}` |
| `assignments:write` | `POST /assignments`, `PATCH /assignments/{id}`, `DELETE /assignments/{id}` |
| `invoices:read` | `GET /invoices`, `GET /invoices/{id}` |
| `purchase_orders:read` | `GET /client-purchase-orders`, `GET /client-purchase-orders/{id}`, `GET /client-purchase-orders/{id}/changes`, `GET /consultant-purchase-orders`, `GET /consultant-purchase-orders/{id}`, `GET /consultant-purchase-orders/{id}/changes` |
| `purchase_orders:write` | `POST /client-purchase-orders`, `PATCH /client-purchase-orders/{id}`, `POST /client-purchase-orders/{id}/close`, `DELETE /client-purchase-orders/{id}`, `POST /consultant-purchase-orders`, `PATCH /consultant-purchase-orders/{id}`, `POST /consultant-purchase-orders/{id}/close`, `DELETE /consultant-purchase-orders/{id}` |
| `events:read` | `GET /events` |

## Write-only keys

A write scope does not include its read scope. A key that can write clients but not read them gets back only the id and status of what it changed, and for an assignment only the id.
