# Orders

Start an order, upload and check the files, get the quote, pay, follow the production, and write messages and the assembly guide.


An order is one part, or one set of parts, in one process, with the design files. All paths are under `https://summonmade.com/api/v1`. The examples read the key from `SUMMONMADE_API_KEY`.

## The way of an order

| Status | What it means | What moves it on |
| --- | --- | --- |
| `draft` | The order takes files. | `POST /orders/{id}/submit` |
| `quoting` | Summonmade calculates the price. | The quote engine, or a person at Summonmade |
| `quoted` | The quote is ready and can be paid. | The payment on the Stripe page |
| `paid` | The payment arrived. | Summonmade starts production |
| `in_production` | The parts are being made. | Summonmade ships the parcel |
| `shipped` | The parcel is on the way; `tracking` holds the link. | The carrier delivers it |
| `delivered` | The parcel arrived. | |
| `cancelled` | The order stopped. | |

The customer can cancel in `draft`, `quoting` and `quoted`. After payment, only Summonmade can cancel, and Summonmade then refunds the payment.

## The order object

| Field | Type | Values |
| --- | --- | --- |
| `id` | string | `SM-` and 8 characters from `23456789ABCDEFGHJKLMNPQRSTUVWXYZ`, for example `SM-7KQ2XW4P`. |
| `title` | string | 1 to 80 characters: a short name for the part. |
| `process` | string | `pcb`, `pcb-assembly`, `3d-print`, `cnc` or `sheet-metal`. |
| `material` | string | 1 to 80 characters, for example `FR-4` or `Aluminium 6061`. See [The catalog](#the-catalog). |
| `finish` | string | The surface finish, for example `ENIG` or `Anodized`. Empty for the standard finish. |
| `quantity` | integer | 1 to 10000 pieces of each part. |
| `shipCountry` | string | The ISO code of an EU member state, or `US`. |
| `notes` | string | Up to 2000 characters for the maker. Empty when none was given. |
| `status` | string | See [The way of an order](#the-way-of-an-order). |
| `files` | array | Each file: `name`, `size` (bytes), `type` (the media type of the upload), `uploadedAt` and `check`. See [The file check](#the-file-check). |
| `quote` | object or null | The price, once the quote is ready. See [The quote](#the-quote). |
| `payment` | object or null | `paidAt`, `amountCents`, `currency`, `method` (`stripe`) and `reference`, once the order is paid. |
| `shipTo` | object or null | The delivery address from the payment page. |
| `tracking` | object or null | `carrier`, `number` and `url`, once the parcel ships. |
| `refunds` | array | Each refund: `at`, `amountCents` and `note`. |
| `instructionsUpdatedAt` | string or null | When the assembly guide last changed. |
| `createdAt`, `updatedAt` | string | ISO 8601 times. |

File names have letters, digits, dots, hyphens and underscores. They start with a letter or digit and have at most 100 characters before the extension. They end in `.step`, `.stp`, `.stl`, `.3mf`, `.dxf`, `.zip`, `.csv` or `.pdf`. A file has at most 50 MB, and an order has at most 20 files.

## The catalog

`GET /catalog` needs no key. It answers `200` with the processes, the materials and finishes that get a quote at once, the smallest batch, the files that each process needs, and the delivery countries. Another material also works: a person at Summonmade then completes the quote.

```sh
curl https://summonmade.com/api/v1/catalog
```

## List orders

`GET /orders` answers `200` with `{ "orders": [...] }`. Each item has `id`, `status`, `title`, `process`, `totalCents` (null before the quote), `createdAt` and `updatedAt`. The last changed order comes first. Add `?status=quoted` for the orders with one status.

```sh
curl https://summonmade.com/api/v1/orders -H "Authorization: Bearer $SUMMONMADE_API_KEY"
```

## Create an order

`POST /orders` with `title`, `process`, `material`, `quantity`, `shipCountry`, and an optional `finish` and `notes`. It answers `201` with the order, as a `draft`.

```sh
curl -X POST https://summonmade.com/api/v1/orders \
  -H "Authorization: Bearer $SUMMONMADE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title": "Desk clock board", "process": "pcb-assembly", "material": "FR-4",
       "finish": "ENIG", "quantity": 5, "shipCountry": "DE", "notes": "Black solder mask."}'
```

## Read an order

`GET /orders/{id}` answers `200` with `{ "order": {...}, "events": [...], "instructions": {...} }`. `instructions` is the assembly guide, or null. Each event has:

| Field | What it holds |
| --- | --- |
| `id` | The event's number in the order. It only grows. |
| `at` | The time. |
| `type` | `created`, `updated`, `file_added`, `file_removed`, `submitted`, `quote_review`, `quoted`, `paid`, `in_production`, `shipped`, `delivered`, `cancelled`, `refunded`, `message`, `instructions` or `note`. |
| `detail` | What happened, in words. For a `message`, the text of the message. |
| `by` | Who did it: `kind` is `person`, `agent` or `summonmade`, and `name` is the person's name, the name of the agent's API key, or Summonmade. |
| `status` | The status of the order after the event. |

`quote_review` means that the quote engine could not price everything, and a person at Summonmade completes the quote. Its `detail` names what is open.

```sh
curl https://summonmade.com/api/v1/orders/SM-7KQ2XW4P -H "Authorization: Bearer $SUMMONMADE_API_KEY"
```

## Change an order

`PUT /orders/{id}` with all the fields of a new order. It works before payment. A `draft` stays a draft; an order in `quoting` or `quoted` gets a new quote. It answers `200` with the order.

```sh
curl -X PUT https://summonmade.com/api/v1/orders/SM-7KQ2XW4P \
  -H "Authorization: Bearer $SUMMONMADE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title": "Desk clock board", "process": "pcb-assembly", "material": "FR-4",
       "finish": "ENIG", "quantity": 10, "shipCountry": "DE"}'
```

## Upload a file

`PUT /orders/{id}/files/{name}` with the raw file as the body. Send `Content-Length` and `Content-Type`. Summonmade checks the file at once and answers `200` with the order; the file's `check` holds the result. A file with the same name is replaced. Files change only while the order is a `draft`.

```sh
curl -X PUT https://summonmade.com/api/v1/orders/SM-7KQ2XW4P/files/gerber.zip \
  -H "Authorization: Bearer $SUMMONMADE_API_KEY" \
  -H "Content-Type: application/zip" \
  --data-binary @gerber.zip
```

## The file check

Each file's `check` tells what the file holds and whether a machine can make it:

| Field | What it holds |
| --- | --- |
| `ok` | False when the file cannot be made as it is. A failed check blocks submit. |
| `kind` | `mesh` (STL, 3MF), `gerber`, `bom`, `placement`, `step`, `dxf` or `pdf`. |
| `format` | The format that the check found, for example `Binary STL` or `STEP AP214`. |
| `summary` | What the check found, in one or two sentences. |
| `problems` | Why the file fails, and what to change. Empty when it passes. |
| `warnings` | Things to look at that do not block the order. |
| `sizeMm` | The size in millimetres: x, y and z for a part; width and height for a board or a flat drawing. |
| `volumeCm3`, `triangles`, `closed`, `parts` | For meshes: the volume of the material, the triangles, whether the mesh is closed, and the number of parts. |
| `layers`, `copperLayers`, `outline`, `drill` | For Gerber zips: the layers, the copper layers, and whether the outline and the drill files are there. |
| `columns`, `rows`, `components`, `componentCostCents` | For BOM and placement files. `componentCostCents` is the component cost of one board, when the BOM has a unit price on every line. |
| `units`, `pages` | The unit that the file declares, and the pages of a PDF. |

For example, a Gerber zip that passes:

```json
{
  "ok": true,
  "kind": "gerber",
  "format": "Gerber zip",
  "summary": "A 2-layer board, 50 × 30 mm, with 7 Gerber and drill files.",
  "problems": [],
  "warnings": [],
  "sizeMm": [50, 30],
  "units": "mm",
  "layers": ["Top copper", "Bottom copper", "Top solder mask", "Bottom solder mask", "Top silkscreen", "Board outline", "Drill"],
  "copperLayers": 2,
  "outline": true,
  "drill": true
}
```

## Remove a file

`DELETE /orders/{id}/files/{name}` removes a file from a `draft`. It answers `200` with the order.

```sh
curl -X DELETE https://summonmade.com/api/v1/orders/SM-7KQ2XW4P/files/old.stl -H "Authorization: Bearer $SUMMONMADE_API_KEY"
```

## Download a file

`GET /orders/{id}/files/{name}` answers `200` with the raw file, its media type and `Content-Disposition: attachment`.

```sh
curl -o gerber.zip https://summonmade.com/api/v1/orders/SM-7KQ2XW4P/files/gerber.zip \
  -H "Authorization: Bearer $SUMMONMADE_API_KEY"
```

## Submit an order

`POST /orders/{id}/submit` sends a draft with the files to the quote. Every file must pass the check, and the order needs the files of the process (for example a Gerber zip for `pcb`). The quote engine runs at once:

- When the engine can price everything, the order answers as `quoted`, with the `quote`.
- Else the order stays `quoting`, the last event is `quote_review`, and a person at Summonmade completes the quote. The order then becomes `quoted`, and a webhook and an email tell you.

```sh
curl -X POST https://summonmade.com/api/v1/orders/SM-7KQ2XW4P/submit -H "Authorization: Bearer $SUMMONMADE_API_KEY"
```

## The quote

| Field | What it holds |
| --- | --- |
| `lines` | The lines in this sequence: `parts`, `shipping`, `service` and `taxes`. Each line has `kind`, `label`, `detail` (how the amount comes about) and `amountCents`. |
| `totalCents` | The total in US cents: the amount that the person pays. |
| `currency` | `USD`. |
| `estimate` | True when a line holds an estimate, such as US import duties. |
| `validUntil` | The quote can be paid until this time, 7 days after it was made. |
| `by` | `engine` for an automatic quote, `summonmade` for a quote from the team. |
| `note` | A note from Summonmade, or empty. |

Show the person the total and the lines before they pay. Never promise a price before the order is `quoted`.

## Pay for an order

`POST /orders/{id}/pay` answers `200` with `{ "url": "...", "test": false }`: a secure Stripe payment page for the quote total. Give the link to the person. An agent with a payment card can also open it and pay. The page asks for the delivery address in the order's delivery country.

```sh
curl -X POST https://summonmade.com/api/v1/orders/SM-7KQ2XW4P/pay -H "Authorization: Bearer $SUMMONMADE_API_KEY"
```

The order becomes `paid` when Stripe confirms the payment, usually within seconds. Read the order, or wait for the webhook.

- Only a claimed account can pay. An agent's own account answers `403` until a person claims it. See [Agents](/docs/api/agents#claim).
- When the quote expired, the call makes a new quote and answers `409`. Read the order, show the person the new total, then call it again.

## Cancel an order

`POST /orders/{id}/cancel` answers `200` with the order, now `cancelled`. It works in `draft`, `quoting` and `quoted`. A cancelled order cannot change again.

```sh
curl -X POST https://summonmade.com/api/v1/orders/SM-7KQ2XW4P/cancel -H "Authorization: Bearer $SUMMONMADE_API_KEY"
```

## Messages

`POST /orders/{id}/messages` with `{ "text": "..." }` writes a message on the order: a question, or the answer to a question from production. It answers `201` with the order. The message is an event of type `message`, with the text in `detail`. Questions from Summonmade come the same way, with `by.kind` `summonmade`, and reach the person by email.

```sh
curl -X POST https://summonmade.com/api/v1/orders/SM-7KQ2XW4P/messages \
  -H "Authorization: Bearer $SUMMONMADE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Yes, cut the M4 thread."}'
```

## The assembly guide

`PUT /orders/{id}/instructions` with `{ "markdown": "..." }` stores the assembly guide: up to 100000 characters of Markdown. The order page shows headings, numbered steps, lists, tables, quotes, links and images by https address. HTML shows as text. An empty `markdown` removes the guide. It answers `200` with the order.

`GET /orders/{id}/instructions` answers `200` with `{ "instructions": { "markdown", "updatedAt", "by" } }`, or `null` in place of the object when there is no guide.

```sh
curl -X PUT https://summonmade.com/api/v1/orders/SM-7KQ2XW4P/instructions \
  -H "Authorization: Bearer $SUMMONMADE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"markdown": "# Assemble the clock\n\n1. Put the board in the case.\n2. Fix it with four M2 screws."}'
```

Write numbered steps, one action in each step. Give the screw sizes and the tools.

## Errors of these operations

| Status | When |
| --- | --- |
| `400` | A field or the order ID is not valid, the body is not JSON, an upload has no body or no `Content-Length`. |
| `403` | The account is an agent's account that no person has claimed, and the call is `pay`. |
| `404` | Your account has no order with this ID, or the order has no file with this name. |
| `409` | The order is not in the right status for the call, a file failed its check or the process needs another file (submit), the order has 20 files already (upload), the quote expired (pay), or the order is paid already (cancel). |
| `413` | The file is larger than 50 MB. |
| `503` | Payment is not set up yet. |

The `detail` of each error says what to change. See [Errors](/docs/api/errors).
