Admin API: Content types
Operations to create, change, and delete content types, and to update their schemas. Common rules (authentication, error format, dates and times) are in the Admin API reference.
The shape of the schema (schema) is in Field types and value formats.
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 content types | GET /admin/api/spaces/{slug}/content-types |
| Create a content type | POST /admin/api/spaces/{slug}/content-types |
| Get a content type | GET /admin/api/spaces/{slug}/content-types/{endpoint} |
| Change a content type’s name and endpoint | PATCH /admin/api/spaces/{slug}/content-types/{endpoint} |
| Delete a content type and all its entries | DELETE /admin/api/spaces/{slug}/content-types/{endpoint} |
| Replace a content type’s schema | PUT /admin/api/spaces/{slug}/content-types/{endpoint}/schema |
| Schema change history | GET /admin/api/spaces/{slug}/content-types/{endpoint}/schema/versions |
List content types
Section titled “List content types”GET /admin/api/spaces/{slug}/content-types- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
Array of ContentTypeListItem (application/json) |
|
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
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>/content-types" \ -H "Authorization: Bearer <access token>"Create a content type
Section titled “Create a content type”POST /admin/api/spaces/{slug}/content-types- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space |
Request body (application/json):
| Name | Type | Required | Constraints | Description |
|---|---|---|---|---|
endpoint |
string | Yes | Endpoint (the content type ID, the name in the Content API path, for example, blog-posts) |
|
kind |
ContentTypeKind | Yes | ||
name |
string | Yes | Display name | |
schema |
object | Schema ({"fields": [...]}). You can see the current shape with content-types get |
Responses:
| Status | Body | Reason |
|---|---|---|
201 |
ContentType (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) |
The endpoint is in use, or a usage limit was reached (limit in the body) |
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 POST "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/content-types" \ -H "Authorization: Bearer <access token>" \ -H "Content-Type: application/json" \ -d '{ "endpoint": "<endpoint>", "name": "<name>", "kind": "collection"}'Get a content type
Section titled “Get a content type”GET /admin/api/spaces/{slug}/content-types/{endpoint}- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
endpoint |
path | string | Yes | Content type endpoint (for example, blog-posts) |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
ContentType (application/json) |
|
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
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>/content-types/<endpoint>" \ -H "Authorization: Bearer <access token>"Change a content type’s name and endpoint
Section titled “Change a content type’s name and endpoint”Changing the endpoint also changes the Content API path.
PATCH /admin/api/spaces/{slug}/content-types/{endpoint}- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
endpoint |
path | string | Yes | Content type endpoint (for example, blog-posts) |
Request body (application/json):
| Name | Type | Required | Constraints | Description |
|---|---|---|---|---|
endpoint |
string or null | Endpoint (content type ID). Changing it also changes the Content API path | ||
name |
string or null | Display name |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
ContentType (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) |
The endpoint is in use |
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>/content-types/<endpoint>" \ -H "Authorization: Bearer <access token>" \ -H "Content-Type: application/json" \ -d '{}'Delete a content type and all its entries
Section titled “Delete a content type and all its entries”Cannot be deleted while other content types reference it.
DELETE /admin/api/spaces/{slug}/content-types/{endpoint}- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
endpoint |
path | string | Yes | Content type endpoint (for example, blog-posts) |
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) |
Referenced by the schema or entries of another content type |
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>/content-types/<endpoint>" \ -H "Authorization: Bearer <access token>"Replace a content type’s schema
Section titled “Replace a content type’s schema”PUT /admin/api/spaces/{slug}/content-types/{endpoint}/schema- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
endpoint |
path | string | Yes | Content type endpoint (for example, blog-posts) |
Request body (application/json):
| Name | Type | Required | Constraints | Description |
|---|---|---|---|---|
confirm |
boolean | Apply anyway, knowingly, when current entries violate the new schema | ||
schema |
object | Yes | Schema ({"fields": [...]}). You can see the current shape with content-types get |
|
schemaVersion |
integer | Yes | Version when you started editing. Returns 409 if someone has updated it since |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
UpdateSchemaResponse (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) |
The schema was changed by someone else (schemaVersion is stale), you tried to change the reference target of a field that has references, there are entries that violate the change and confirm is false (violationCount and entryIds in the body), or values of a unique field are duplicated (duplicates in the body) |
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 PUT "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/content-types/<endpoint>/schema" \ -H "Authorization: Bearer <access token>" \ -H "Content-Type: application/json" \ -d '{ "schema": {}, "schemaVersion": 1}'Schema change history
Section titled “Schema change history”GET /admin/api/spaces/{slug}/content-types/{endpoint}/schema/versions- Login: required (session or access token)
Parameters:
| Name | In | Type | Required | Constraints | Description |
|---|---|---|---|---|---|
slug |
path | string | Yes | Slug of the space | |
endpoint |
path | string | Yes | Content type endpoint (for example, blog-posts) |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
Array of SchemaVersion (application/json) |
|
401 |
Error (application/json) |
Not logged in, or the access token is wrong, expired, or revoked |
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>/content-types/<endpoint>/schema/versions" \ -H "Authorization: Bearer <access token>"