# The CRM API

> Read and change your CRM's clients, people, deals, agreements and timeline from another system, such as your accounting package or website, with an API key.

The CRM API lets another system read and change your CRM: its clients, the people at them, their deals with each deal's lines and invoices, their agreements, and the timeline of what happened with each. Your accounting package can keep clients and invoices in step, your website can add a lead the moment a form is sent, an integration platform can move a deal when something happens elsewhere, and a script of your own can read whatever it needs, without anybody copying anything across.

Every call acts as the person whose key it is. It can do what they can do on the CRM's own pages and nothing more, and every change it makes is checked, written in the record's history and told to your workflows exactly as the same change on a page would be.

```text
https://crm.sanda-os.com.au/api/crm/v1
```

:::note
The CRM calls companies **clients**. The API calls them companies, as every other system does: a client is a `company`, at `/companies`.
:::

## Start in two minutes

:::steps
1. **Make a key.** In the CRM, go to **Settings · API keys**, press **Make a key**, give it a name such as "Xero sync", choose **Read and change**, and press **Make the key**. Copy the key: it begins `bck_` and is shown once. See [API keys](https://docs.sanda-os.com.au/crm-api/keys).
2. **Ask who you are.** Every call sends the key as a bearer token.

   ```bash
   curl https://crm.sanda-os.com.au/api/crm/v1/me \
     -H "Authorization: Bearer bck_..."
   ```

   The answer names you, the workspace, the key's scopes and whether it may change things.
3. **Add a client.**

   ```bash
   curl https://crm.sanda-os.com.au/api/crm/v1/companies \
     -H "Authorization: Bearer bck_..." \
     -H "Content-Type: application/json" \
     -d '{"name": "Acme Services", "domain": "acme.com.au"}'
   ```

   The answer is the new company, with its `id` and a `url` to its page in the CRM.
4. **Find it again.** `GET /companies?domain=acme.com.au` finds it by its domain, and `GET /companies/{id}` reads it by its id.
:::

## What it covers

| You want to | Use |
|---|---|
| List, find, add, change, archive and restore clients, people, deals and agreements | [Records](https://docs.sanda-os.com.au/crm-api/records) |
| Read a record's history: who changed what, and when | [Records](https://docs.sanda-os.com.au/crm-api/records#history) |
| Put lines and invoices on a deal | [Deals](https://docs.sanda-os.com.au/crm-api/deals) |
| Move a deal to another stage, win it or lose it | [Deals](https://docs.sanda-os.com.au/crm-api/deals#move-a-deal) |
| Read the timeline, and log a note, an email, a call or a meeting | [The timeline](https://docs.sanda-os.com.au/crm-api/timeline) |
| Keep another system in step with every change | [The change feed and webhooks](https://docs.sanda-os.com.au/crm-api/changes) |
| Every endpoint, field, filter, event and error | [Reference](https://docs.sanda-os.com.au/crm-api/reference) |

The API does not change the CRM's setup (its pipelines, fields and agreement types), which an owner or admin does on **Settings**, though it reads all of them so another system can use their ids. Tickets, files, Knowledge and workflows are not part of it. For those, connect an assistant to the CRM. See [connect an assistant to the CRM](https://docs.sanda-os.com.au/crm/assistants).

## How every call works

- **JSON in, JSON out.** Send a JSON object with `Content-Type: application/json`, up to 200 KB. Every answer is JSON, and carries a `Sanda-Api-Version` header, which is 1.0.0 today.
- **A thing is named for what it is.** One company comes back as `{"company": {...}}` and a list as `{"companies": [...]}`. A link to another record is an object such as `{"id": "...", "name": "Acme Services"}`, or `null`.
- **Only the fields a call takes.** A field the call does not know is refused with 400, naming it, so a typo never silently does nothing.
- **A change sends only what changes.** `PATCH` changes the fields you send and leaves the rest as they are. Send `null` to clear one.
- **Every record has an id**, a UUID such as `5f0c2b7e-8a51-4c8e-9d0b-2a4c7e1f9b33`, which never changes.
- **Times are ISO 8601 in UTC**, such as `2026-12-03T04:15:00.000Z`. A day, such as a deal's expected close, is `YYYY-MM-DD`, and a day you leave out (the day an invoice was made) is today in your workspace's time zone.
- **Lists come a page at a time.** See [pages](#pages).
- **Calls are limited per key** to 300 a minute. Past that, a call answers 429 with a `Retry-After` header of 60 seconds.

### Pages

Every list returns a page at a time, 50 unless `limit` says otherwise (up to 100). The answer's `next_cursor` is what you send back as `cursor` for the next page. When it is `null` there is no more.

```bash
curl "https://crm.sanda-os.com.au/api/crm/v1/deals?outcome=open&limit=100" -H "Authorization: Bearer bck_..."
# → {"deals": [...], "next_cursor": "eyJvIjoibmV3ZXN0Ii..."}
curl "https://crm.sanda-os.com.au/api/crm/v1/deals?outcome=open&limit=100&cursor=eyJvIjoibmV3ZXN0Ii..." -H "Authorization: Bearer bck_..."
```

A page never shifts under you: a record added while you page is not repeated or skipped. A cursor belongs to the list and order that gave it. Change the order and start without one.

### When a change waits for approval

A [workflow](https://docs.sanda-os.com.au/crm/workflows#ask-for-approval) can make a move wait for somebody to approve it, such as a deal moving to **Won**. A change the API asks for waits the same way: the rest of what you sent is made, and the answer says what is waiting.

- Changing a deal or an agreement answers **202** rather than 200, with the record as it now stands and `pending_approval`, which says who it waits for.
- Adding one answers 201 as usual, and carries `pending_approval` when its first move waits.

When it is decided, the change is made, or not, and the [change feed](https://docs.sanda-os.com.au/crm-api/changes) has it either way.

### Errors

A refusal is a status with a JSON body that says what to do, in the same words the CRM's page would use:

```json
{
  "error": {
    "code": "insufficient_scope",
    "message": "This key was not made with crm:manage, which POST /deals/{id}/archive needs. Make a key with it under Settings · API keys.",
    "required_scope": "crm:manage"
  }
}
```

Branch on `code`, and show a person `message`. Every code is in the [reference](https://docs.sanda-os.com.au/crm-api/reference#errors).

## OpenAPI

The API describes itself as an OpenAPI 3.1 document, which needs no key:

```text
https://crm.sanda-os.com.au/api/crm/v1/openapi.json
```

Import it into Postman, Insomnia or an integration platform to get every endpoint with its fields, or generate a client from it.

:::links
- [API keys](https://docs.sanda-os.com.au/crm-api/keys): Make, scope and revoke the keys a system uses.
- [Records](https://docs.sanda-os.com.au/crm-api/records): List, find, add and change clients, people, deals and agreements.
- [The change feed and webhooks](https://docs.sanda-os.com.au/crm-api/changes): Hear about every change, in order.
:::
