Skip to content
Sandadocs

Deals

Move a deal through its pipeline, win or lose it, and put its lines and invoices on it through the CRM API.

A deal is one record from the first conversation to the last invoice: what a client is buying, its lines, how far it has got, what was delivered and what has been invoiced and paid. Everything records say holds for a deal too. This page is what is a deal's own.

Move a deal

A deal is always at one stage of one pipeline. GET /pipelines lists them, each with its stages in order, and each stage's outcome: open, won or lost.

To move it, change its stage_id:

Shell
curl -X PATCH https://crm.sanda-os.com.au/api/crm/v1/deals/9b2e... \
  -H "Authorization: Bearer bck_..." \
  -H "Content-Type: application/json" \
  -d '{"stage_id": "c4d1...", "closed_on": "2026-12-02"}'
  • Won or lost. A move to a won or lost stage closes the deal, on closed_on or today. Send lost_reason with a move to a lost stage to say why.
  • Back again. "reopen": true reopens a lost deal, at the stage it was lost from.
  • Another pipeline. A stage of another pipeline moves it there, and pipeline_id alone moves it to that pipeline's first stage.
  • After the fact. moved_at says when it really reached the stage, for a deal your system moved some time ago.

A move does what it does on the deal's own page: its client becomes a lead while a deal is open, its history and timeline record it, and your workflows run on it. A move a workflow holds for approval answers 202, with the deal still where it was and pending_approval saying who it waits for. See when a change waits for approval.

A new deal needs a name and its client: company_id, or company_name to add a new client with it. Left out, its pipeline is the default one and its stage that pipeline's first.

Lines

A deal's lines are what it sells. Each line's amount is worked out from its quantity, unit price and discount, and a deal with priced lines is worth what they add up to.

Call Does Key needs
GET /deals/{id}/lines Its lines, in order crm:read
POST /deals/{id}/lines Add a line crm:write
PATCH /deals/{id}/lines/{line_id} Change a line, or say how many were delivered crm:write
DELETE /deals/{id}/lines/{line_id} Take a line off crm:write
Shell
curl https://crm.sanda-os.com.au/api/crm/v1/deals/9b2e.../lines \
  -H "Authorization: Bearer bck_..." \
  -H "Content-Type: application/json" \
  -d '{"description": "Monthly bookkeeping", "quantity": 12, "unit_price": 450, "billing": "monthly"}'
JSON
{
  "line": {
    "id": "e81f...",
    "position": 1,
    "code": null,
    "description": "Monthly bookkeeping",
    "quantity": 12,
    "unit_price": 450,
    "discount": null,
    "discount_label": null,
    "amount": 5400,
    "billing": "monthly",
    "basis": null,
    "received": null,
    "rejected": false,
    "product": null,
    "created_at": "2026-12-03T04:15:00.000Z",
    "updated_at": "2026-12-03T04:15:00.000Z"
  },
  "deal": { "id": "9b2e...", "value": 5400, "...": "..." }
}

Every change to a line answers with the line and the deal as it now stands, so your system has the deal's new value without asking again. Taking a line off answers {"deleted": {"id": ...}, "deal": {...}}.

Field Type Sent when What it takes
description string Adding and changing The item: what is sold. Needed to add one.
code string Adding and changing Its code or SKU.
quantity number Adding and changing How many. Left out of a new one, 1.
unit_price number Adding and changing The price of one, or null while it has none.
discount number Adding and changing The discount, as a percentage.
discount_label string Adding and changing What the discount is called on a quote.
billing string Adding and changing How it is charged: one_off or monthly.
basis string Adding and changing What it is priced on, in your own words, such as per site.
product_id string Adding only The product on a price list it came from.
received number Changing only How many were delivered.
rejected boolean Changing only true when the client turned it down.

A lost deal keeps its lines and invoices as they are: a change to them answers 409 until the deal is reopened.

Invoices

The invoices put against a deal, as your accounting system raised them. The CRM does not send them; it keeps what was invoiced and what was paid, so a deal shows what is still owed.

Call Does Key needs
GET /deals/{id}/invoices Its invoices, oldest first crm:read
POST /deals/{id}/invoices Put an invoice against it crm:write
PATCH /deals/{id}/invoices/{invoice_id} Mark it paid, or not crm:write
DELETE /deals/{id}/invoices/{invoice_id} Take it off crm:write
Shell
curl https://crm.sanda-os.com.au/api/crm/v1/deals/9b2e.../invoices \
  -H "Authorization: Bearer bck_..." \
  -H "Content-Type: application/json" \
  -d '{"amount": 1350, "reference": "INV-1001", "invoiced_on": "2026-12-01"}'

When it is paid:

Shell
curl -X PATCH https://crm.sanda-os.com.au/api/crm/v1/deals/9b2e.../invoices/71c0... \
  -H "Authorization: Bearer bck_..." \
  -H "Content-Type: application/json" \
  -d '{"paid": true}'
Field Type Sent when What it takes
amount number Adding only What it is for. Needed to add one.
reference string Adding only Its number in your accounting system.
invoiced_on string Adding only The day it was raised. Left out, today.
paid boolean Adding and changing true marks it paid (today unless paid_on says), false not paid.
paid_on string Adding and changing The day it was paid.

An invoice's amount and reference are what your accounting system says, so they are not changed afterwards: take one off and put it on again.

Lines and invoices on the change feed

A line or an invoice is part of its deal, so a change to one is a deal.updated event on the change feed. In its changes, a line added or taken off is the field line with the action created or deleted, a line changed is line.quantity, line.unit_price and so on, and an invoice is invoice. Each names the line's description or the invoice's reference in from and to, beside what changed.

Something unclear or out of date? Tell us, and we will fix the page.