# Media

> The media library's pictures, sent through a one-time upload address and checked as the library checks them, and a product's gallery.

| Operation | Method and path | Scope |
|---|---|---|
| [Start an upload](https://docs.kaizenaflow.com/reference/admin-api/media#media-upload) | `POST /media/uploads` | [`products:manage`](https://docs.kaizenaflow.com/reference/scopes#products-manage) |
| [Keep an uploaded picture](https://docs.kaizenaflow.com/reference/admin-api/media#media-create) | `POST /media` | [`products:manage`](https://docs.kaizenaflow.com/reference/scopes#products-manage) |
| [List the media library](https://docs.kaizenaflow.com/reference/admin-api/media#media-list) | `GET /media` | [`products:read`](https://docs.kaizenaflow.com/reference/scopes#products-read) |
| [Get a product's gallery](https://docs.kaizenaflow.com/reference/admin-api/media#products-media) | `GET /products/{id}/media` | [`products:read`](https://docs.kaizenaflow.com/reference/scopes#products-read) |
| [Add a picture to a product](https://docs.kaizenaflow.com/reference/admin-api/media#products-media-add) | `POST /products/{id}/media` | [`products:manage`](https://docs.kaizenaflow.com/reference/scopes#products-manage) |
| [Order a product's pictures](https://docs.kaizenaflow.com/reference/admin-api/media#products-media-order) | `PATCH /products/{id}/media` | [`products:manage`](https://docs.kaizenaflow.com/reference/scopes#products-manage) |
| [Take a picture off a product](https://docs.kaizenaflow.com/reference/admin-api/media#products-media-remove) | `DELETE /products/{id}/media/{media_id}` | [`products:manage`](https://docs.kaizenaflow.com/reference/scopes#products-manage) |

## Start an upload {#media-upload}

`POST https://kaizenaflow.com/api/admin/v1/media/uploads`

Gives a one-time address to PUT a picture to, for 2 hours. The file is checked and kept only by `POST /media`, as the media library checks an upload: its type read from its bytes, shrunk as the admin's browser shrinks pictures (WebP, at most 1600 pixels wide, a 480-pixel copy), counted against the store's storage.

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

### Body {#media-upload-body}

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

| Field | Type | Required | Description |
|---|---|---|---|
| `content_type` | one of `image/jpeg`, `image/png`, `image/webp`, `image/avif` | yes | The picture's type: JPEG, PNG, WebP or AVIF. |
| `size_bytes` | integer, 1 to 20,971,520 | yes | Its size in bytes, at most 20 MB. |

### Answer {#media-upload-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.upload_id` | string (uuid) | Give it to `POST /media` once the file is sent. |
| `data.upload_url` | string or null | A one-time address: PUT the file's bytes there with the same Content-Type, once. Answered once: a replay of the request (the same Idempotency-Key) answers null. |
| `data.method` | `"PUT"` |   |
| `data.headers` | map of string to string | The headers to send with the PUT. |
| `data.expires_at` | string (date-time) | The address and the upload id end then. |

### Errors {#media-upload-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 {#media-upload-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/media/uploads' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"content_type":"image/jpeg","size_bytes":1}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/media/uploads", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "content_type": "image/jpeg",
    "size_bytes": 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/media/uploads",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "content_type": "image/jpeg",
        "size_bytes": 1,
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Keep an uploaded picture {#media-create}

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

Checks the file sent to an upload's address and keeps it in the store's media library, once: an upload id is used up by its first success.

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

### Body {#media-create-body}

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

| Field | Type | Required | Description |
|---|---|---|---|
| `upload_id` | string (uuid) | yes | The upload whose file was sent (`POST /media/uploads`). |
| `file_name` | string, 1 to 255 characters | no | The name the library shows; `picture` when left out. |
| `alt` | string, at most 300 characters | no | Words for people who cannot see it; the store's AI writes them when left out. |

### Answer {#media-create-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.id` | string (uuid) |   |
| `data.kind` | one of `image`, `video`, `model` | image, video or model (3D). |
| `data.url` | string |   |
| `data.thumbnail_url` | string or null | A small copy, 480 pixels wide, for a picture. |
| `data.file_name` | string |   |
| `data.content_type` | string |   |
| `data.size_bytes` | integer |   |
| `data.width` | integer or null |   |
| `data.height` | integer or null |   |
| `data.alt` | string | Its words for people who cannot see it, in the store's main language. |
| `data.created_at` | string (date-time) |   |
| `data.updated_at` | string (date-time) |   |

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

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/media' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"upload_id":"3399b5fa-aaf6-4440-bcb8-9b5321b1bfd9"}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/media", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "upload_id": "3399b5fa-aaf6-4440-bcb8-9b5321b1bfd9"
  }),
});
const answer = await response.json();
```

**Python**

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

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/media",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "upload_id": "3399b5fa-aaf6-4440-bcb8-9b5321b1bfd9",
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## List the media library {#media-list}

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

The store's pictures, videos and 3D models, newest first.

- **Operation:** `media.list`
- **Scope:** [`products:read`](https://docs.kaizenaflow.com/reference/scopes#products-read), or [`products:write`](https://docs.kaizenaflow.com/reference/scopes#products-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 {#media-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. |
| `kind` | one of `image`, `video`, `model` | no | Only this kind. |

### Answer {#media-list-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].id` | string (uuid) |   |
| `data[].kind` | one of `image`, `video`, `model` | image, video or model (3D). |
| `data[].url` | string |   |
| `data[].thumbnail_url` | string or null | A small copy, 480 pixels wide, for a picture. |
| `data[].file_name` | string |   |
| `data[].content_type` | string |   |
| `data[].size_bytes` | integer |   |
| `data[].width` | integer or null |   |
| `data[].height` | integer or null |   |
| `data[].alt` | string | Its words for people who cannot see it, in the store's main language. |
| `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 {#media-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 {#media-list-example}

**curl**

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

**JavaScript**

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

## Get a product's gallery {#products-media}

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

The product's pictures, videos and 3D models in their order, the first the main one.

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

### Path parameters {#products-media-path}

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

### Answer {#products-media-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].media_id` | string (uuid) or null | The library item (`GET /media`); null for a file the library does not hold. |
| `data[].kind` | one of `image`, `video`, `model` |   |
| `data[].url` | string |   |
| `data[].thumbnail_url` | string or null |   |
| `data[].alt` | string |   |
| `data[].position` | integer | Its place in the gallery: 0 is the main picture. |

### Errors {#products-media-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 {#products-media-example}

**curl**

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

**JavaScript**

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

## Add a picture to a product {#products-media-add}

`POST https://kaizenaflow.com/api/admin/v1/products/{id}/media`

Adds a library picture after the product's pictures, through the product editor's save. A product on the site only with `products:publish` (else `gated`). Answers the gallery as it is now.

- **Operation:** `products.media_add`
- **Scope:** [`products:manage`](https://docs.kaizenaflow.com/reference/scopes#products-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 {#products-media-add-path}

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

### Body {#products-media-add-body}

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

| Field | Type | Required | Description |
|---|---|---|---|
| `media_id` | string (uuid) | yes | A picture of the store's media library. |
| `alt` | string, at most 300 characters | no | Its words in the product's gallery; the library's, else the product's title, when left out. |

### Answer {#products-media-add-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].media_id` | string (uuid) or null | The library item (`GET /media`); null for a file the library does not hold. |
| `data[].kind` | one of `image`, `video`, `model` |   |
| `data[].url` | string |   |
| `data[].thumbnail_url` | string or null |   |
| `data[].alt` | string |   |
| `data[].position` | integer | Its place in the gallery: 0 is the main picture. |

### Errors {#products-media-add-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 {#products-media-add-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/products/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/media' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"media_id":"2690d087-c00f-46bc-b218-44e4db282d91"}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/products/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/media", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "media_id": "2690d087-c00f-46bc-b218-44e4db282d91"
  }),
});
const answer = await response.json();
```

**Python**

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

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

## Order a product's pictures {#products-media-order}

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

Puts the product's pictures in the order given (each of them named once); a product on the site only with `products:publish`.

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

### Path parameters {#products-media-order-path}

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

### Body {#products-media-order-body}

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

| Field | Type | Required | Description |
|---|---|---|---|
| `media_ids` | list of string (uuid), 1 to 20 items | yes | The gallery's pictures, by library id, in the order they should have; the first is the main one. Videos and 3D models keep their places after them. |

### Answer {#products-media-order-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].media_id` | string (uuid) or null | The library item (`GET /media`); null for a file the library does not hold. |
| `data[].kind` | one of `image`, `video`, `model` |   |
| `data[].url` | string |   |
| `data[].thumbnail_url` | string or null |   |
| `data[].alt` | string |   |
| `data[].position` | integer | Its place in the gallery: 0 is the main picture. |

### Errors {#products-media-order-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). |
| 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 {#products-media-order-example}

**curl**

```shell
curl -X PATCH 'https://kaizenaflow.com/api/admin/v1/products/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/media' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"media_ids":["a9f8f01c-d10d-4794-ad3f-340d53a95a25"]}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/products/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/media", {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "media_ids": [
      "a9f8f01c-d10d-4794-ad3f-340d53a95a25"
    ]
  }),
});
const answer = await response.json();
```

**Python**

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

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

## Take a picture off a product {#products-media-remove}

`DELETE https://kaizenaflow.com/api/admin/v1/products/{id}/media/{media_id}`

Takes the picture out of the product's gallery (it stays in the library); a product on the site only with `products:publish`.

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

### Path parameters {#products-media-remove-path}

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

### Answer {#products-media-remove-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].media_id` | string (uuid) or null | The library item (`GET /media`); null for a file the library does not hold. |
| `data[].kind` | one of `image`, `video`, `model` |   |
| `data[].url` | string |   |
| `data[].thumbnail_url` | string or null |   |
| `data[].alt` | string |   |
| `data[].position` | integer | Its place in the gallery: 0 is the main picture. |

### Errors {#products-media-remove-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). |
| 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 {#products-media-remove-example}

**curl**

```shell
curl -X DELETE 'https://kaizenaflow.com/api/admin/v1/products/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/media/2690d087-c00f-46bc-b218-44e4db282d91' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/products/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/media/2690d087-c00f-46bc-b218-44e4db282d91", {
  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/products/3f2b8c1e-6d4a-4b9e-8c7f-1a2b3c4d5e6f/media/2690d087-c00f-46bc-b218-44e4db282d91",
    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/media · made from the API contract 1.57
