# Discounts

> Discount codes, made through the admin's own form.

| Operation | Method and path | Scope |
|---|---|---|
| [List discount codes](https://docs.kaizenaflow.com/reference/admin-api/discounts#discounts-list) | `GET /discounts` | [`discounts:read`](https://docs.kaizenaflow.com/reference/scopes#discounts-read) |
| [Create a discount code](https://docs.kaizenaflow.com/reference/admin-api/discounts#discounts-create) | `POST /discounts` | [`discounts:write`](https://docs.kaizenaflow.com/reference/scopes#discounts-write) |
| [Get a discount code](https://docs.kaizenaflow.com/reference/admin-api/discounts#discounts-get) | `GET /discounts/{id}` | [`discounts:read`](https://docs.kaizenaflow.com/reference/scopes#discounts-read) |
| [Change a discount code](https://docs.kaizenaflow.com/reference/admin-api/discounts#discounts-update) | `PATCH /discounts/{id}` | [`discounts:publish`](https://docs.kaizenaflow.com/reference/scopes#discounts-publish) |
| [Switch a discount code off](https://docs.kaizenaflow.com/reference/admin-api/discounts#discounts-disable) | `POST /discounts/{id}/disable` | [`discounts:publish`](https://docs.kaizenaflow.com/reference/scopes#discounts-publish) |

## List discount codes {#discounts-list}

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

The store's discount codes, newest first.

- **Operation:** `discounts.list`
- **Scope:** [`discounts:read`](https://docs.kaizenaflow.com/reference/scopes#discounts-read), or [`discounts:write`](https://docs.kaizenaflow.com/reference/scopes#discounts-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 {#discounts-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. |

### Answer {#discounts-list-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].id` | string (uuid) |   |
| `data[].code` | string |   |
| `data[].kind` | one of `percent`, `fixed`, `free_shipping` |   |
| `data[].percent` | number or null |   |
| `data[].amounts_minor` | map of string to number | For a fixed amount off: the amount per market, in minor units of the market's currency. |
| `data[].active` | boolean |   |
| `data[].starts_at` | string (date-time) or null |   |
| `data[].ends_at` | string (date-time) or null |   |
| `data[].usage_limit` | number or null |   |
| `data[].created_at` | string (date-time) |   |
| `data[].updated_at` | string (date-time) |   |
| `next` | string or null | The cursor of the next page, given as `?after=`; null on the last page. |

### Errors {#discounts-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 {#discounts-list-example}

**curl**

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

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/discounts", {
  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/discounts",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Create a discount code {#discounts-create}

`POST https://kaizenaflow.com/api/admin/v1/discounts`

Makes a discount code through the admin's own form and its checks: a percent, a fixed amount per market, or free shipping.

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

### Body {#discounts-create-body}

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

| Field | Type | Required | Description |
|---|---|---|---|
| `code` | string, 1 to 100 characters | yes | What shoppers type: 3 to 40 letters, digits, - or \_. Kept in capitals, without spaces. |
| `kind` | one of `percent`, `fixed`, `free_shipping` | yes |   |
| `percent` | integer, 1 to 100 | no | For percent: how much is taken off; 10 when left out. |
| `amounts` | map of string to string | no | For fixed: the amount off per market code, written in the market's currency, such as { "NO": "100" }. |
| `min_subtotals` | map of string to string | no | The least a basket must hold per market code, written in the market's currency. |
| `starts_at` | string or null | no | When it starts, as the store's local time (YYYY-MM-DDTHH:mm); at once when left out. |
| `ends_at` | string or null | no | When it ends, as the store's local time; never when left out. |
| `usage_limit` | integer, 1 to 1,000,000 or null | no | How many times it may be used in all; no limit when left out. |
| `once_per_customer` | boolean | no |   |
| `active` | boolean | no | False makes it switched off; on when left out. |

### Answer {#discounts-create-answer}

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

### Errors {#discounts-create-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. |
| 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 {#discounts-create-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/discounts' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"code":"SPRING10","kind":"percent"}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/discounts", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "code": "SPRING10",
    "kind": "percent"
  }),
});
const answer = await response.json();
```

**Python**

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

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/discounts",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "code": "SPRING10",
        "kind": "percent",
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Get a discount code {#discounts-get}

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

One discount code with how often it was used.

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

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

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

### Answer {#discounts-get-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.id` | string (uuid) |   |
| `data.code` | string |   |
| `data.kind` | one of `percent`, `fixed`, `free_shipping` |   |
| `data.percent` | number or null |   |
| `data.amounts_minor` | map of string to number | For a fixed amount off: per market code, in minor units of the market's currency. |
| `data.min_subtotals_minor` | map of string to number |   |
| `data.active` | boolean |   |
| `data.starts_at` | string (date-time) or null |   |
| `data.ends_at` | string (date-time) or null |   |
| `data.usage_limit` | number or null |   |
| `data.once_per_customer` | boolean |   |
| `data.used` | integer | Paid orders that used it. |
| `data.applies_to` | one of `everything`, `some` | some: chosen products, categories or tags (set in the admin). |
| `data.for_some_customers` | boolean | Only groups, named customers or a segment (set in the admin). |

### Errors {#discounts-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 {#discounts-get-example}

**curl**

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

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/discounts/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/discounts/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Change a discount code {#discounts-update}

`PATCH https://kaizenaflow.com/api/admin/v1/discounts/{id}`

Changes only what is given, through the admin's own form and its checks; what it reaches and who may use it stay as set in the admin. Orders already placed keep what they got. A loyalty reward's code is changed with its reward.

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

### Path parameters {#discounts-update-path}

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

### Body {#discounts-update-body}

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

| Field | Type | Required | Description |
|---|---|---|---|
| `code` | string, 1 to 100 characters | no |   |
| `percent` | integer, 1 to 100 | no | For percent: how much is taken off. |
| `amounts` | map of string to string | no | For fixed: the amount off per market code, written in the market's currency; replaces what is there. |
| `min_subtotals` | map of string to string | no |   |
| `starts_at` | string or null | no | As the store's local time (YYYY-MM-DDTHH:mm), or ISO 8601; null: at once. |
| `ends_at` | string or null | no | null: never. |
| `usage_limit` | integer, 1 to 1,000,000 or null | no |   |
| `once_per_customer` | boolean | no |   |
| `active` | boolean | no |   |

### Answer {#discounts-update-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.id` | string (uuid) |   |
| `data.code` | string |   |
| `data.kind` | one of `percent`, `fixed`, `free_shipping` |   |
| `data.percent` | number or null |   |
| `data.amounts_minor` | map of string to number | For a fixed amount off: per market code, in minor units of the market's currency. |
| `data.min_subtotals_minor` | map of string to number |   |
| `data.active` | boolean |   |
| `data.starts_at` | string (date-time) or null |   |
| `data.ends_at` | string (date-time) or null |   |
| `data.usage_limit` | number or null |   |
| `data.once_per_customer` | boolean |   |
| `data.used` | integer | Paid orders that used it. |
| `data.applies_to` | one of `everything`, `some` | some: chosen products, categories or tags (set in the admin). |
| `data.for_some_customers` | boolean | Only groups, named customers or a segment (set in the admin). |

### Errors {#discounts-update-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 {#discounts-update-example}

**curl**

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

**JavaScript**

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

**Python**

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

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

## Switch a discount code off {#discounts-disable}

`POST https://kaizenaflow.com/api/admin/v1/discounts/{id}/disable`

Switches the code off, as its form's switch does: shoppers can no longer use it; nothing else changes.

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

### Path parameters {#discounts-disable-path}

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

### Body {#discounts-disable-body}

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

| Field | Type | Required | Description |
|---|---|---|---|
| `body` | object | yes |   |

### Answer {#discounts-disable-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.id` | string (uuid) |   |
| `data.code` | string |   |
| `data.kind` | one of `percent`, `fixed`, `free_shipping` |   |
| `data.percent` | number or null |   |
| `data.amounts_minor` | map of string to number | For a fixed amount off: per market code, in minor units of the market's currency. |
| `data.min_subtotals_minor` | map of string to number |   |
| `data.active` | boolean |   |
| `data.starts_at` | string (date-time) or null |   |
| `data.ends_at` | string (date-time) or null |   |
| `data.usage_limit` | number or null |   |
| `data.once_per_customer` | boolean |   |
| `data.used` | integer | Paid orders that used it. |
| `data.applies_to` | one of `everything`, `some` | some: chosen products, categories or tags (set in the admin). |
| `data.for_some_customers` | boolean | Only groups, named customers or a segment (set in the admin). |

### Errors {#discounts-disable-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 {#discounts-disable-example}

**curl**

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

**JavaScript**

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

**Python**

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

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

---

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