# Orders

> Orders in their own currency, parcels with tracking, and invoices and credit notes as EN 16931 UBL.

| Operation | Method and path | Scope |
|---|---|---|
| [List orders](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-list) | `GET /orders` | [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read) |
| [Get an order](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-get) | `GET /orders/{id}` | [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read) |
| [Send a parcel](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-fulfil) | `POST /orders/{id}/fulfillments` | [`orders:write`](https://docs.kaizenaflow.com/reference/scopes#orders-write) |
| [Get an invoice as UBL](https://docs.kaizenaflow.com/reference/admin-api/orders#invoices-ubl) | `GET /invoices/{id}/ubl` | [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read) |
| [Get a credit note as UBL](https://docs.kaizenaflow.com/reference/admin-api/orders#credit-notes-ubl) | `GET /credit-notes/{id}/ubl` | [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read) |
| [List an order's refunds](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-refunds) | `GET /orders/{id}/refunds` | [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read) |
| [Refund an order](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-refund) | `POST /orders/{id}/refunds` | [`orders:refund`](https://docs.kaizenaflow.com/reference/scopes#orders-refund) |
| [Cancel an unpaid order](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-cancel) | `POST /orders/{id}/cancel` | [`orders:refund`](https://docs.kaizenaflow.com/reference/scopes#orders-refund) |
| [List an order's notes](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-notes) | `GET /orders/{id}/notes` | [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read) |
| [Add a note to an order](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-note) | `POST /orders/{id}/notes` | [`orders:manage`](https://docs.kaizenaflow.com/reference/scopes#orders-manage) |
| [Tag an order](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-tag) | `POST /orders/{id}/tags` | [`orders:manage`](https://docs.kaizenaflow.com/reference/scopes#orders-manage) |
| [Remove an order's tag](https://docs.kaizenaflow.com/reference/admin-api/orders#orders-untag) | `DELETE /orders/{id}/tags/{tag}` | [`orders:manage`](https://docs.kaizenaflow.com/reference/scopes#orders-manage) |

## List orders {#orders-list}

`GET https://kaizenaflow.com/api/admin/v1/orders`

The store's orders, newest first, in each order's own currency. History copied from another store is left out.

- **Operation:** `orders.list`
- **Scope:** [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read), or [`orders:write`](https://docs.kaizenaflow.com/reference/scopes#orders-write), which reads too
- **Answers:** `200`, a page: the rows under `data`, and `next` for the page after.
- **Pages:** at most 100 rows, 50 when `limit` is left out; give an answer's `next` as `?after=` for the page after.

### Query parameters {#orders-list-query}

| Name | Type | Required | Description |
|---|---|---|---|
| `limit` | integer, 1 to 100 | no | Rows a page holds, at most 100; 50 when left out. A larger number gives 100. |
| `after` | string, at most 200 characters | no | The `next` cursor of the page before; the first page when left out. |
| `updated_after` | string (date-time) | no | Only what was made or changed after this time (ISO 8601 with its offset), for incremental sync. |
| `status` | one of `pending_payment`, `authorized`, `paid`, `fulfilled`, `closed`, `cancelled` | no | Only orders in this state. |
| `unfulfilled` | one of `true`, `false` | no | true: only paid orders with something still to send. |

### Answer {#orders-list-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].id` | string (uuid) |   |
| `data[].number` | string | The order's number, one sequence per store. |
| `data[].status` | one of `pending_payment`, `authorized`, `paid`, `fulfilled`, `closed`, `cancelled` |   |
| `data[].fulfilment` | one of `none`, `unsent`, `partly_sent`, `sent`, `withdrawn`, `closed` | What is sent: none (nothing to send), unsent, partly_sent, sent, withdrawn or closed. |
| `data[].copied` | boolean | History copied from another store: read-only. |
| `data[].placed_at` | string (date-time) |   |
| `data[].market` | string | A market, by its code (the country's ISO 3166-1 code, such as NO). |
| `data[].currency` | string, matching `^[A-Z]{3}$` | An ISO 4217 code, such as NOK or EUR. |
| `data[].email` | string |   |
| `data[].subtotal_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].shipping_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].tax_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].total_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].paid_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].refunded_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].shipping_address` | object |   |
| `data[].shipping_address.name` | string |   |
| `data[].shipping_address.line1` | string |   |
| `data[].shipping_address.line2` | string |   |
| `data[].shipping_address.postal_code` | string |   |
| `data[].shipping_address.city` | string |   |
| `data[].shipping_address.country` | string |   |
| `data[].shipping_address.phone` | string |   |
| `data[].billing_address` | object |   |
| `data[].billing_address.name` | string |   |
| `data[].billing_address.line1` | string |   |
| `data[].billing_address.line2` | string |   |
| `data[].billing_address.postal_code` | string |   |
| `data[].billing_address.city` | string |   |
| `data[].billing_address.country` | string |   |
| `data[].billing_address.phone` | string |   |
| `data[].lines` | list of objects |   |
| `data[].lines[].id` | string (uuid) |   |
| `data[].lines[].variant_id` | string (uuid) or null |   |
| `data[].lines[].sku` | string |   |
| `data[].lines[].title` | string |   |
| `data[].lines[].quantity` | integer |   |
| `data[].lines[].unit_price_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].lines[].total_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].lines[].delivery` | one of `physical`, `digital`, `service` |   |
| `data[].lines[].to_send` | integer | Units still to send. |
| `data[].shipments` | list of objects |   |
| `data[].shipments[].id` | string (uuid) |   |
| `data[].shipments[].carrier` | string |   |
| `data[].shipments[].tracking_number` | string |   |
| `data[].shipments[].tracking_url` | string or null |   |
| `data[].shipments[].created_at` | string (date-time) |   |
| `data[].shipments[].lines` | list of objects |   |
| `data[].shipments[].lines[].line_id` | string (uuid) |   |
| `data[].shipments[].lines[].quantity` | integer |   |
| `data[].tags` | list of string | Staff's tags on the order. |
| `data[].updated_at` | string (date-time) | When it last changed: placed, paid, sent, refunded, edited or noted (its timeline's latest entry). |
| `next` | string or null | The cursor of the next page, given as `?after=`; null on the last page. |

### Errors {#orders-list-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-list-example}

**curl**

```shell
curl 'https://kaizenaflow.com/api/admin/v1/orders' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders", {
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Get an order {#orders-get}

`GET https://kaizenaflow.com/api/admin/v1/orders/{id}`

One order with its lines, what is left to send, its parcels and tags.

- **Operation:** `orders.get`
- **Scope:** [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read), or [`orders:write`](https://docs.kaizenaflow.com/reference/scopes#orders-write), which reads too
- **Answers:** `200`, the answer under `data`.

### Path parameters {#orders-get-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Answer {#orders-get-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.id` | string (uuid) |   |
| `data.number` | string | The order's number, one sequence per store. |
| `data.status` | one of `pending_payment`, `authorized`, `paid`, `fulfilled`, `closed`, `cancelled` |   |
| `data.fulfilment` | one of `none`, `unsent`, `partly_sent`, `sent`, `withdrawn`, `closed` | What is sent: none (nothing to send), unsent, partly_sent, sent, withdrawn or closed. |
| `data.copied` | boolean | History copied from another store: read-only. |
| `data.placed_at` | string (date-time) |   |
| `data.market` | string | A market, by its code (the country's ISO 3166-1 code, such as NO). |
| `data.currency` | string, matching `^[A-Z]{3}$` | An ISO 4217 code, such as NOK or EUR. |
| `data.email` | string |   |
| `data.subtotal_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.shipping_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.tax_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.total_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.paid_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.refunded_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.shipping_address` | object |   |
| `data.shipping_address.name` | string |   |
| `data.shipping_address.line1` | string |   |
| `data.shipping_address.line2` | string |   |
| `data.shipping_address.postal_code` | string |   |
| `data.shipping_address.city` | string |   |
| `data.shipping_address.country` | string |   |
| `data.shipping_address.phone` | string |   |
| `data.billing_address` | object |   |
| `data.billing_address.name` | string |   |
| `data.billing_address.line1` | string |   |
| `data.billing_address.line2` | string |   |
| `data.billing_address.postal_code` | string |   |
| `data.billing_address.city` | string |   |
| `data.billing_address.country` | string |   |
| `data.billing_address.phone` | string |   |
| `data.lines` | list of objects |   |
| `data.lines[].id` | string (uuid) |   |
| `data.lines[].variant_id` | string (uuid) or null |   |
| `data.lines[].sku` | string |   |
| `data.lines[].title` | string |   |
| `data.lines[].quantity` | integer |   |
| `data.lines[].unit_price_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.lines[].total_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.lines[].delivery` | one of `physical`, `digital`, `service` |   |
| `data.lines[].to_send` | integer | Units still to send. |
| `data.shipments` | list of objects |   |
| `data.shipments[].id` | string (uuid) |   |
| `data.shipments[].carrier` | string |   |
| `data.shipments[].tracking_number` | string |   |
| `data.shipments[].tracking_url` | string or null |   |
| `data.shipments[].created_at` | string (date-time) |   |
| `data.shipments[].lines` | list of objects |   |
| `data.shipments[].lines[].line_id` | string (uuid) |   |
| `data.shipments[].lines[].quantity` | integer |   |
| `data.tags` | list of string | Staff's tags on the order. |
| `data.updated_at` | string (date-time) | When it last changed: placed, paid, sent, refunded, edited or noted (its timeline's latest entry). |

### Errors {#orders-get-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-get-example}

**curl**

```shell
curl 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f", {
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Send a parcel {#orders-fulfil}

`POST https://kaizenaflow.com/api/admin/v1/orders/{id}/fulfillments`

Records a parcel with its carrier and tracking, as the admin's Send does, and emails the customer unless `notify` is false. Answers the order as it is now.

- **Operation:** `orders.fulfil`
- **Scope:** [`orders:write`](https://docs.kaizenaflow.com/reference/scopes#orders-write)
- **Answers:** `201`, made: the answer under `data`.
- **Once only:** with an [`Idempotency-Key`](https://docs.kaizenaflow.com/reference/admin-api#idempotency) header.

### Path parameters {#orders-fulfil-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Body {#orders-fulfil-body}

JSON, with `Content-Type: application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `carrier` | one of `posten`, `bring`, `porterbuddy`, `helthjem`, `instabox`, `postnord`, `dhl`, `dhl_paket`, `ups`, `nshift`, `other` | yes |   |
| `tracking_number` | string, at most 100 characters | no, default `""` |   |
| `tracking_url` | `""` or string (uri) | no, default `""` | The parcel's tracking page; the carrier's own when left out. |
| `lines` | list of objects, at most 500 items | no | What is in the parcel; everything still to send when left out. |
| `lines[].line_id` | string (uuid) | yes |   |
| `lines[].quantity` | integer, 1 to 100,000 | yes |   |
| `notify` | boolean | no, default `true` | Email the customer about the parcel, as the admin's Send does. |

### Answer {#orders-fulfil-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.id` | string (uuid) |   |
| `data.number` | string | The order's number, one sequence per store. |
| `data.status` | one of `pending_payment`, `authorized`, `paid`, `fulfilled`, `closed`, `cancelled` |   |
| `data.fulfilment` | one of `none`, `unsent`, `partly_sent`, `sent`, `withdrawn`, `closed` | What is sent: none (nothing to send), unsent, partly_sent, sent, withdrawn or closed. |
| `data.copied` | boolean | History copied from another store: read-only. |
| `data.placed_at` | string (date-time) |   |
| `data.market` | string | A market, by its code (the country's ISO 3166-1 code, such as NO). |
| `data.currency` | string, matching `^[A-Z]{3}$` | An ISO 4217 code, such as NOK or EUR. |
| `data.email` | string |   |
| `data.subtotal_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.shipping_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.tax_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.total_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.paid_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.refunded_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.shipping_address` | object |   |
| `data.shipping_address.name` | string |   |
| `data.shipping_address.line1` | string |   |
| `data.shipping_address.line2` | string |   |
| `data.shipping_address.postal_code` | string |   |
| `data.shipping_address.city` | string |   |
| `data.shipping_address.country` | string |   |
| `data.shipping_address.phone` | string |   |
| `data.billing_address` | object |   |
| `data.billing_address.name` | string |   |
| `data.billing_address.line1` | string |   |
| `data.billing_address.line2` | string |   |
| `data.billing_address.postal_code` | string |   |
| `data.billing_address.city` | string |   |
| `data.billing_address.country` | string |   |
| `data.billing_address.phone` | string |   |
| `data.lines` | list of objects |   |
| `data.lines[].id` | string (uuid) |   |
| `data.lines[].variant_id` | string (uuid) or null |   |
| `data.lines[].sku` | string |   |
| `data.lines[].title` | string |   |
| `data.lines[].quantity` | integer |   |
| `data.lines[].unit_price_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.lines[].total_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.lines[].delivery` | one of `physical`, `digital`, `service` |   |
| `data.lines[].to_send` | integer | Units still to send. |
| `data.shipments` | list of objects |   |
| `data.shipments[].id` | string (uuid) |   |
| `data.shipments[].carrier` | string |   |
| `data.shipments[].tracking_number` | string |   |
| `data.shipments[].tracking_url` | string or null |   |
| `data.shipments[].created_at` | string (date-time) |   |
| `data.shipments[].lines` | list of objects |   |
| `data.shipments[].lines[].line_id` | string (uuid) |   |
| `data.shipments[].lines[].quantity` | integer |   |
| `data.tags` | list of string | Staff's tags on the order. |
| `data.updated_at` | string (date-time) | When it last changed: placed, paid, sent, refunded, edited or noted (its timeline's latest entry). |

### Errors {#orders-fulfil-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 403 | [`gated`](https://docs.kaizenaflow.com/reference/errors#gated) | The request needs a power beside the operation's scope (the message names it): changing a product, category or address on the site, an import that would, or a customer's email. A copied order is never changed. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 409 | [`conflict`](https://docs.kaizenaflow.com/reference/errors#conflict) | Nothing was done: it clashes with how things are now (nothing left to send), or an `Idempotency-Key` is in use or was used for another request. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-fulfil-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/fulfillments' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"carrier":"posten"}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/fulfillments", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "carrier": "posten"
  }),
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/fulfillments",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "carrier": "posten",
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Get an invoice as UBL {#invoices-ubl}

`GET https://kaizenaflow.com/api/admin/v1/invoices/{id}/ubl`

An invoice as an EN 16931 electronic invoice (UBL 2.1), for accounting systems.

- **Operation:** `invoices.ubl`
- **Scope:** [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read), or [`orders:write`](https://docs.kaizenaflow.com/reference/scopes#orders-write), which reads too
- **Answers:** `200`, the answer under `data`.

### Path parameters {#invoices-ubl-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Answer {#invoices-ubl-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.file_name` | string |   |
| `data.content_type` | `"application/xml"` |   |
| `data.xml` | string | The document as EN 16931 UBL 2.1. |

### Errors {#invoices-ubl-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#invoices-ubl-example}

**curl**

```shell
curl 'https://kaizenaflow.com/api/admin/v1/invoices/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/ubl' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/invoices/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/ubl", {
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/invoices/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/ubl",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Get a credit note as UBL {#credit-notes-ubl}

`GET https://kaizenaflow.com/api/admin/v1/credit-notes/{id}/ubl`

A credit note as an EN 16931 electronic document (UBL 2.1).

- **Operation:** `credit_notes.ubl`
- **Scope:** [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read), or [`orders:write`](https://docs.kaizenaflow.com/reference/scopes#orders-write), which reads too
- **Answers:** `200`, the answer under `data`.

### Path parameters {#credit-notes-ubl-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Answer {#credit-notes-ubl-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.file_name` | string |   |
| `data.content_type` | `"application/xml"` |   |
| `data.xml` | string | The document as EN 16931 UBL 2.1. |

### Errors {#credit-notes-ubl-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#credit-notes-ubl-example}

**curl**

```shell
curl 'https://kaizenaflow.com/api/admin/v1/credit-notes/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/ubl' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/credit-notes/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/ubl", {
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/credit-notes/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/ubl",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## List an order's refunds {#orders-refunds}

`GET https://kaizenaflow.com/api/admin/v1/orders/{id}/refunds`

Every refund of the order, newest first, in its own currency.

- **Operation:** `orders.refunds`
- **Scope:** [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read), or [`orders:write`](https://docs.kaizenaflow.com/reference/scopes#orders-write), which reads too
- **Answers:** `200`, the answer under `data`.

### Path parameters {#orders-refunds-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Answer {#orders-refunds-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].id` | string (uuid) |   |
| `data[].order_id` | string (uuid) |   |
| `data[].amount_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data[].currency` | string, matching `^[A-Z]{3}$` | An ISO 4217 code, such as NOK or EUR. |
| `data[].status` | string | pending (on its way), succeeded or failed. |
| `data[].kind` | string | How the money went back: to the payment, or as store credit. |
| `data[].restocked` | boolean | Units went back in stock with it. |
| `data[].created_at` | string (date-time) |   |

### Errors {#orders-refunds-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-refunds-example}

**curl**

```shell
curl 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/refunds' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/refunds", {
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/refunds",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Refund an order {#orders-refund}

`POST https://kaizenaflow.com/api/admin/v1/orders/{id}/refunds`

Refunds part or all of what is left through `refundOrder()`, the admin's own refund: through the payment it was taken by (Stripe, Mollie, or recorded for money taken outside), or as store credit; units put back in stock where they came from. Needs `orders:refund`.

- **Operation:** `orders.refund`
- **Scope:** [`orders:refund`](https://docs.kaizenaflow.com/reference/scopes#orders-refund)
- **Answers:** `201`, made: the answer under `data`.
- **Once only:** with an [`Idempotency-Key`](https://docs.kaizenaflow.com/reference/admin-api#idempotency) header.

### Path parameters {#orders-refund-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Body {#orders-refund-body}

JSON, with `Content-Type: application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `amount_minor` | integer, at least 0 | yes | What goes back, in minor units of the order's currency; 0 to put units back in stock only. |
| `reason` | string, 1 to 500 characters | no, default `"Refund"` | Why, for the order's history and the credit note. |
| `restock` | list of objects, at most 500 items | no, default `[]` | Units put back in stock, per order line. |
| `restock[].line_id` | string (uuid) | yes |   |
| `restock[].quantity` | integer, 1 to 100,000 | yes |   |
| `restock[].location_id` | string (uuid) or null | no | Where they go back; where they were taken from when left out. |
| `not_sent` | boolean | no, default `false` | The units put back were never sent: they come off what is still to send. |
| `to_store_credit` | boolean | no, default `false` | Give the amount as store credit (D364), emailed to the order's address, instead of to the payment. |
| `notify` | boolean | no, default `true` | Email the customer about the refund, as the admin's Refund does (store credit is emailed either way). |

### Answer {#orders-refund-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.refund_ids` | list of string (uuid) | Every refund made: an amount split over the order's payments makes one each. |
| `data.amount_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.status` | string or null |   |
| `data.closed_units` | integer | Units taken off what was still to send (`not_sent`). |
| `data.store_credit` | object or null | Store credit issued; its code goes only to the customer. |
| `data.store_credit.card_id` | string (uuid) |   |
| `data.store_credit.amount_minor` | integer | An amount in minor units of the currency (øre, cents), VAT included where the store's prices are. |
| `data.store_credit.emailed` | one of `sent`, `failed` |   |

### Errors {#orders-refund-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 403 | [`gated`](https://docs.kaizenaflow.com/reference/errors#gated) | The request needs a power beside the operation's scope (the message names it): changing a product, category or address on the site, an import that would, or a customer's email. A copied order is never changed. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 409 | [`conflict`](https://docs.kaizenaflow.com/reference/errors#conflict) | Nothing was done: it clashes with how things are now (nothing left to send), or an `Idempotency-Key` is in use or was used for another request. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-refund-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/refunds' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"amount_minor":1}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/refunds", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "amount_minor": 1
  }),
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/refunds",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "amount_minor": 1,
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Cancel an unpaid order {#orders-cancel}

`POST https://kaizenaflow.com/api/admin/v1/orders/{id}/cancel`

Cancels an order waiting for payment: its payment page is closed first (one found paid is refused), its stock goes back and its pay link dies. A paid order is refunded instead (`orders:refund`).

- **Operation:** `orders.cancel`
- **Scope:** [`orders:refund`](https://docs.kaizenaflow.com/reference/scopes#orders-refund)
- **Answers:** `200`, the answer under `data`.
- **Once only:** with an [`Idempotency-Key`](https://docs.kaizenaflow.com/reference/admin-api#idempotency) header.

### Path parameters {#orders-cancel-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Body {#orders-cancel-body}

JSON, with `Content-Type: application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `reason` | string, at most 500 characters | no, default `"Cancelled by the store"` | Why, for the order's history. |
| `notify` | boolean | no, default `false` | Email the customer that the order is cancelled. |

### Answer {#orders-cancel-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.id` | string (uuid) |   |
| `data.status` | `"cancelled"` |   |

### Errors {#orders-cancel-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 403 | [`gated`](https://docs.kaizenaflow.com/reference/errors#gated) | The request needs a power beside the operation's scope (the message names it): changing a product, category or address on the site, an import that would, or a customer's email. A copied order is never changed. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 409 | [`conflict`](https://docs.kaizenaflow.com/reference/errors#conflict) | Nothing was done: it clashes with how things are now (nothing left to send), or an `Idempotency-Key` is in use or was used for another request. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-cancel-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/cancel' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"reason":"Cancelled by the store"}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/cancel", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "reason": "Cancelled by the store"
  }),
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/cancel",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "reason": "Cancelled by the store",
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## List an order's notes {#orders-notes}

`GET https://kaizenaflow.com/api/admin/v1/orders/{id}/notes`

Staff's notes on the order, newest first.

- **Operation:** `orders.notes`
- **Scope:** [`orders:read`](https://docs.kaizenaflow.com/reference/scopes#orders-read), or [`orders:write`](https://docs.kaizenaflow.com/reference/scopes#orders-write), which reads too
- **Answers:** `200`, the answer under `data`.

### Path parameters {#orders-notes-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Answer {#orders-notes-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].note` | string |   |
| `data[].by` | string | Who wrote it: a person's email, or the token's name. |
| `data[].created_at` | string (date-time) |   |

### Errors {#orders-notes-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-notes-example}

**curl**

```shell
curl 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/notes' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/notes", {
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/notes",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Add a note to an order {#orders-note}

`POST https://kaizenaflow.com/api/admin/v1/orders/{id}/notes`

Adds a note for staff to the order's history, as the order page does; the customer never sees it.

- **Operation:** `orders.note`
- **Scope:** [`orders:manage`](https://docs.kaizenaflow.com/reference/scopes#orders-manage)
- **Answers:** `201`, made: the answer under `data`.
- **Once only:** with an [`Idempotency-Key`](https://docs.kaizenaflow.com/reference/admin-api#idempotency) header.

### Path parameters {#orders-note-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Body {#orders-note-body}

JSON, with `Content-Type: application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `note` | string, 1 to 2,000 characters | yes | A note for staff; the customer never sees it. |

### Answer {#orders-note-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.note` | string |   |
| `data.by` | string | Who wrote it: a person's email, or the token's name. |
| `data.created_at` | string (date-time) |   |

### Errors {#orders-note-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 403 | [`gated`](https://docs.kaizenaflow.com/reference/errors#gated) | The request needs a power beside the operation's scope (the message names it): changing a product, category or address on the site, an import that would, or a customer's email. A copied order is never changed. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 409 | [`conflict`](https://docs.kaizenaflow.com/reference/errors#conflict) | Nothing was done: it clashes with how things are now (nothing left to send), or an `Idempotency-Key` is in use or was used for another request. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-note-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/notes' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"note":"Counted on Monday"}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/notes", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "note": "Counted on Monday"
  }),
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/notes",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "note": "Counted on Monday",
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Tag an order {#orders-tag}

`POST https://kaizenaflow.com/api/admin/v1/orders/{id}/tags`

Adds a tag to the order (at most 250 an order); one it has is kept once. Answers its tags.

- **Operation:** `orders.tag`
- **Scope:** [`orders:manage`](https://docs.kaizenaflow.com/reference/scopes#orders-manage)
- **Answers:** `201`, made: the answer under `data`.
- **Once only:** with an [`Idempotency-Key`](https://docs.kaizenaflow.com/reference/admin-api#idempotency) header.

### Path parameters {#orders-tag-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |

### Body {#orders-tag-body}

JSON, with `Content-Type: application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `tag` | string, 1 to 120 characters | yes | The tag's words; one the order has is kept once. |

### Answer {#orders-tag-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.tags` | list of string |   |

### Errors {#orders-tag-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 409 | [`conflict`](https://docs.kaizenaflow.com/reference/errors#conflict) | Nothing was done: it clashes with how things are now (nothing left to send), or an `Idempotency-Key` is in use or was used for another request. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-tag-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/tags' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"tag":"vip"}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/tags", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "tag": "vip"
  }),
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/tags",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "tag": "vip",
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Remove an order's tag {#orders-untag}

`DELETE https://kaizenaflow.com/api/admin/v1/orders/{id}/tags/{tag}`

Takes a tag off the order, named as it is written in any case. Answers its tags.

- **Operation:** `orders.untag`
- **Scope:** [`orders:manage`](https://docs.kaizenaflow.com/reference/scopes#orders-manage)
- **Answers:** `200`, the answer under `data`.

### Path parameters {#orders-untag-path}

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | yes | The thing's id in this store. |
| `tag` | string, 1 to 200 characters | yes | The tag's words, URL-encoded. |

### Answer {#orders-untag-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.tags` | list of string |   |

### Errors {#orders-untag-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 404 | [`not_found`](https://docs.kaizenaflow.com/reference/errors#not-found) | No such route, or nothing with that id in the token's store (another store's ids are simply not found). |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#orders-untag-example}

**curl**

```shell
curl -X DELETE 'https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/tags/vip' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/tags/vip", {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/orders/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/tags/vip",
    method="DELETE",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

---

https://docs.kaizenaflow.com/reference/admin-api/orders · made from the API contract 1.57
