Admin API: Media
Operations that upload, list, change, and delete media. Common rules (authentication, error format, dates and times) are in the Admin API reference.
In the examples, replace <hostname> with the hostname of your environment and <access token> with an access token that starts with hako_pat_. Replace other values in angle brackets, such as <slug>, with the values described in each operation’s parameter table.
| Operation | Method and path |
|---|---|
| List media | GET /admin/api/spaces/{slug}/media |
| Upload media | POST /admin/api/spaces/{slug}/media |
| Get media | GET /admin/api/spaces/{slug}/media/{id} |
| Change the alt text and tags of media | PATCH /admin/api/spaces/{slug}/media/{id} |
| Delete media | DELETE /admin/api/spaces/{slug}/media/{id} |
| Entries that use the media | GET /admin/api/spaces/{slug}/media/{id}/usages |
List media
Section titled “List media”GET /admin/api/spaces/{slug}/media- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
q |
query | string | Search by file name, alt text, or tag | ||
tag |
query | string | Items with this tag | ||
kind |
query | string | image or file |
||
limit |
query | integer | 0 or more | Number of items (default 50, maximum 100) | |
cursor |
query | string | nextCursor from the previous response |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
ListResponse (application/json) |
|
400 |
Error (application/json) |
An input value breaks a rule (including JSON syntax errors). Errors with their locations are in issues |
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
403 |
Error (application/json) |
Insufficient permission (including writes with a read-only access token and writes from another origin with a session) |
404 |
Error (application/json) |
Not found. A space you are not a member of also returns 404 |
If the request fails, you get a 4xx or 5xx status and a JSON body with message. The meaning of each status is in the list of errors.
Example:
curl "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/media" \ -H "Authorization: Bearer <access token>"Upload media
Section titled “Upload media”POST /admin/api/spaces/{slug}/media- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space |
Request body (multipart/form-data):
| Name | Type | Required | Constraints | Description |
|---|---|---|---|---|
alt |
string or null | Alt text | ||
file |
file | Yes | File | |
tags |
string or null | Tags (a JSON array of strings, ["news","top"]) |
Responses:
| Status | Body | Reason |
|---|---|---|
201 |
MediaView (application/json) |
|
400 |
Error (application/json) |
An input value breaks a rule (including JSON syntax errors). Errors with their locations are in issues |
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
403 |
Error (application/json) |
Insufficient permission (including writes with a read-only access token and writes from another origin with a session) |
404 |
Error (application/json) |
Not found. A space you are not a member of also returns 404 |
409 |
Error (application/json) |
A usage limit set by the operator was reached (limit in the body has the name and value of the limit) |
413 |
Error (application/json) |
The file is too large |
If the request fails, you get a 4xx or 5xx status and a JSON body with message. The meaning of each status is in the list of errors.
Example:
curl -X POST "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/media" \ -H "Authorization: Bearer <access token>" \ -F "file=@<file>"Get media
Section titled “Get media”GET /admin/api/spaces/{slug}/media/{id}- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
id |
path | string | Yes | ID |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
MediaView (application/json) |
|
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
403 |
Error (application/json) |
Insufficient permission (including writes with a read-only access token and writes from another origin with a session) |
404 |
Error (application/json) |
Not found. A space you are not a member of also returns 404 |
If the request fails, you get a 4xx or 5xx status and a JSON body with message. The meaning of each status is in the list of errors.
Example:
curl "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/media/<id>" \ -H "Authorization: Bearer <access token>"Change the alt text and tags of media
Section titled “Change the alt text and tags of media”PATCH /admin/api/spaces/{slug}/media/{id}- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
id |
path | string | Yes | ID |
Request body (application/json):
| Name | Type | Required | Constraints | Description |
|---|---|---|---|---|
alt |
string or null | Alt text | ||
tags |
array of strings or null | Tags (an array of strings). If you pass this, it replaces the existing tags |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
MediaView (application/json) |
|
400 |
Error (application/json) |
An input value breaks a rule (including JSON syntax errors). Errors with their locations are in issues |
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
403 |
Error (application/json) |
Insufficient permission (including writes with a read-only access token and writes from another origin with a session) |
404 |
Error (application/json) |
Not found. A space you are not a member of also returns 404 |
415 |
Error (application/json) |
Content-Type: application/json is missing |
422 |
Error (application/json) |
The JSON has the wrong shape (a required key is missing, a type is wrong, or there is an unknown key) |
If the request fails, you get a 4xx or 5xx status and a JSON body with message. The meaning of each status is in the list of errors.
Example:
curl -X PATCH "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/media/<id>" \ -H "Authorization: Bearer <access token>" \ -H "Content-Type: application/json" \ -d '{}'Delete media
Section titled “Delete media”DELETE /admin/api/spaces/{slug}/media/{id}- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
id |
path | string | Yes | ID |
Responses:
| Status | Body | Reason |
|---|---|---|
204 |
None | |
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
403 |
Error (application/json) |
Insufficient permission (including writes with a read-only access token and writes from another origin with a session) |
404 |
Error (application/json) |
Not found. A space you are not a member of also returns 404 |
409 |
Error (application/json) |
Entries use it (usageCount in the body) |
If the request fails, you get a 4xx or 5xx status and a JSON body with message. The meaning of each status is in the list of errors.
Example:
curl -X DELETE "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/media/<id>" \ -H "Authorization: Bearer <access token>"Entries that use the media
Section titled “Entries that use the media”GET /admin/api/spaces/{slug}/media/{id}/usages- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
id |
path | string | Yes | ID |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
Array of Usage (application/json) |
|
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
403 |
Error (application/json) |
Insufficient permission (including writes with a read-only access token and writes from another origin with a session) |
404 |
Error (application/json) |
Not found. A space you are not a member of also returns 404 |
If the request fails, you get a 4xx or 5xx status and a JSON body with message. The meaning of each status is in the list of errors.
Example:
curl "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/media/<id>/usages" \ -H "Authorization: Bearer <access token>"