Admin API: Roles
Operations to create, change, and delete the roles of a space. 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 roles | GET /admin/api/spaces/{slug}/roles |
| Create a role | POST /admin/api/spaces/{slug}/roles |
| Get a role | GET /admin/api/spaces/{slug}/roles/{id} |
| Change a role’s name and permissions | PUT /admin/api/spaces/{slug}/roles/{id} |
| Delete a role | DELETE /admin/api/spaces/{slug}/roles/{id} |
List roles
Section titled “List roles”GET /admin/api/spaces/{slug}/roles- 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 RoleView (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>/roles" \ -H "Authorization: Bearer <access token>"Create a role
Section titled “Create a role”POST /admin/api/spaces/{slug}/roles- 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 |
|---|---|---|---|---|
actions |
RoleActions | Actions on entries ({"default": ["read", ...], "contentTypes": {"<ID>": [...]}}). By default, nothing is allowed on any of them |
||
name |
string | Yes | Role name | |
permissions |
array of strings | Permissions on the whole space (array of strings). Defaults to empty |
Responses:
| Status | Body | Reason |
|---|---|---|
201 |
RoleView (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 name 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 POST "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/roles" \ -H "Authorization: Bearer <access token>" \ -H "Content-Type: application/json" \ -d '{ "name": "<name>"}'Get a role
Section titled “Get a role”GET /admin/api/spaces/{slug}/roles/{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 |
RoleView (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>/roles/<id>" \ -H "Authorization: Bearer <access token>"Change a role’s name and permissions
Section titled “Change a role’s name and permissions”PUT /admin/api/spaces/{slug}/roles/{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 |
|---|---|---|---|---|
actions |
RoleActions | Actions on entries ({"default": ["read", ...], "contentTypes": {"<ID>": [...]}}). By default, nothing is allowed on any of them |
||
name |
string | Yes | Role name | |
permissions |
array of strings | Permissions on the whole space (array of strings). Defaults to empty |
Responses:
| Status | Body | Reason |
|---|---|---|
200 |
RoleView (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 name 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 PUT "https://<hostname>.hakocms.net/admin/api/spaces/<slug>/roles/<id>" \ -H "Authorization: Bearer <access token>" \ -H "Content-Type: application/json" \ -d '{ "name": "<name>"}'Delete a role
Section titled “Delete a role”DELETE /admin/api/spaces/{slug}/roles/{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) |
The role is in use by members (memberCount 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>/roles/<id>" \ -H "Authorization: Bearer <access token>"