# Media

> Images, videos and files. 4 endpoints in the Unvop API.

Images, videos and files.

## List media

`GET /v1/sites/{siteId}/media`

Scope: `content:read`.

Uploaded images, videos and files, newest first (up to 500). Search with q; filter with type.

### Path parameters

- `siteId` (string, required): The site’s id.

### Query parameters

- `q` (string)
- `type` (string): One of `image`, `video`, `other`.

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `url` (string, required): A site-relative address, like /media/<key>.
  - `filename` (string, required)
  - `mime` (string, required)
  - `size` (number, required)
  - `width` (number)
  - `height` (number)
  - `alt` (string, required)
  - `createdAt` (string, required): An ISO 8601 timestamp.
- `cursor` (string, nullable): Pass as ?cursor= to get the next page. Null when there are no more.
- `total` (integer): How many there are in all, when the list knows.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/media \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Upload media

`POST /v1/sites/{siteId}/media`

Scope: `media:write`.

Add an image, video or file: send it as multipart/form-data (field "file", optional "alt"), or send JSON { url, alt } and Unvop downloads it (https only). Up to 15 MB. JPG, PNG, WebP, GIF, AVIF, SVG, PDF, MP4 and WebM. Use the returned url in image props.

### Path parameters

- `siteId` (string, required): The site’s id.

### Headers

- `Idempotency-Key` (string): Send the same key to repeat this request safely; the first answer is replayed for 24 hours. (up to 200 characters)

### Request body (multipart/form-data)

- `url` (string, required): (uri; up to 2,000 characters)
- `alt` (string): (up to 500 characters)
- `filename` (string): (up to 200 characters)

### Response 201

- `id` (string, required)
- `url` (string, required): A site-relative address, like /media/<key>.
- `filename` (string, required)
- `mime` (string, required)
- `size` (number, required)
- `width` (number)
- `height` (number)
- `alt` (string, required)
- `createdAt` (string, required): An ISO 8601 timestamp.
- `absoluteUrl` (string, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `413`: Too large.
- `415`: That file type isn’t supported.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/media \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -F "file=@sourdough.jpg" \
  -F "alt=A sourdough loaf on the counter"
```

## Describe media

`PATCH /v1/sites/{siteId}/media/{mediaId}`

Scope: `media:write`.

Change a file’s alt text, which screen readers and search engines read.

### Path parameters

- `siteId` (string, required): The site’s id.
- `mediaId` (string, required)

### Request body (JSON)

- `alt` (string, required): (up to 500 characters)

### Response 200

- `id` (string, required)
- `url` (string, required): A site-relative address, like /media/<key>.
- `filename` (string, required)
- `mime` (string, required)
- `size` (number, required)
- `width` (number)
- `height` (number)
- `alt` (string, required)
- `createdAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X PATCH https://api.unvop.com/v1/sites/site_123/media/med_123 \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "alt": "A sourdough loaf on the counter"
  }'
```

## Delete media

`DELETE /v1/sites/{siteId}/media/{mediaId}`

Scope: `media:write`.

Delete a file. Pages that still use it show nothing in its place.

### Path parameters

- `siteId` (string, required): The site’s id.
- `mediaId` (string, required)

### Response 200

- `ok` (true, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X DELETE https://api.unvop.com/v1/sites/site_123/media/med_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```
