Role management API
This page documents the 8 gateway endpoints tagged role management in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| GET | /role/permissions | The permission catalogue for custom roles |
| GET | /role/list | List custom roles |
| GET | /role/info | Get a custom role with its user count |
| POST | /role/new | Create a custom role |
| POST | /role/update | Update a custom role |
| DELETE | /role/delete | Delete a custom role |
| POST | /role/assign | Give a user a custom role |
| POST | /role/unassign | Take a custom role away from a user |
Endpoints
GET /role/permissions
The permission catalogue for custom roles
The permission names a custom role may grant or deny, with the routes each one covers, plus the base roles a custom role can start from. Proxy admins and admin viewers may call it, and nothing changes. Needs the custom_roles license feature.
Example request:
curl -X GET "http://localhost:4000/role/permissions" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json PermissionCatalogueResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller is not a proxy admin or admin viewer, or the license does not include custom_roles | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
permissions | array of PermissionInfo | Yes | Permissions |
wildcard | string | Yes | Wildcard |
assignable_base_roles | array of string | Yes | Assignable Base Roles |
GET /role/list
List custom roles
Every custom role with its base role and its granted and denied permissions. Proxy admins and admin viewers may call it, and nothing changes. Needs the custom_roles license feature.
Example request:
curl -X GET "http://localhost:4000/role/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json array of Spanway_RoleTable |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller is not a proxy admin or admin viewer, or the license does not include custom_roles | application/json ErrorDetail |
| 500 | The database is not connected | application/json ErrorDetail |
GET /role/info
Get a custom role with its user count
One custom role and how many users hold it. Proxy admins and admin viewers may call it, and nothing changes. Needs the custom_roles license feature.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
role_id | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/role/info?role_id=role_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json RoleInfoResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller is not a proxy admin or admin viewer, or the license does not include custom_roles | application/json ErrorDetail |
| 404 | No custom role has that role_id | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
role_id | string | Yes | Role Id |
role_name | string | Yes | Role Name |
description | string or null | No | Description |
base_role | string | Yes | Base Role |
permissions | array of string | No | Permissions |
denied_permissions | array of string | No | Denied Permissions |
created_by | string or null | No | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
assigned_user_count | integer | Yes | Assigned User Count |
POST /role/new
Create a custom role
Creates a custom role, for example a support engineer who may read keys and logs and block keys but not see credentials: a base role plus granted and denied permissions. Only proxy admins may call it. It needs the custom_roles license feature, and the change is written to the audit log.
Request body (application/json, schema NewRoleRequest):
| Field | Type | Required | Description |
|---|---|---|---|
role_name | string | Yes | Role Name |
description | string or null | No | Description |
base_role | string | Yes | Base Role |
permissions | array of string | No | Permissions |
denied_permissions | array of string | No | Denied Permissions |
Example request:
curl -X POST "http://localhost:4000/role/new" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"role_name": "support-engineer",
"description": "Read keys, users and logs, and block keys",
"base_role": "internal_user_viewer",
"permissions": [
"keys.read",
"keys.write",
"users.read",
"logs.read"
],
"denied_permissions": [
"credentials.read",
"credentials.write"
]
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_RoleTable |
| 400 | Another custom role already has that name | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Only proxy admins may change custom roles, and the license must include custom_roles | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
role_id | string | Yes | Role Id |
role_name | string | Yes | Role Name |
description | string or null | No | Description |
base_role | string | Yes | Base Role |
permissions | array of string | No | Permissions |
denied_permissions | array of string | No | Denied Permissions |
created_by | string or null | No | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
POST /role/update
Update a custom role
Changes a custom role's name, base role or permissions. Users holding it pick up the change on their next request. Only proxy admins may call it. It needs the custom_roles license feature, and the change is written to the audit log.
Request body (application/json, schema UpdateRoleRequest):
| Field | Type | Required | Description |
|---|---|---|---|
role_id | string | Yes | Role Id |
role_name | string or null | No | Role Name |
description | string or null | No | Description |
base_role | string or null | No | Base Role |
permissions | array of string or null | No | Permissions |
denied_permissions | array of string or null | No | Denied Permissions |
Example request:
curl -X POST "http://localhost:4000/role/update" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"role_id": "8f6c2b1e-4d2a-4f7e-9b1c-2a3d4e5f6a7b",
"description": "Read keys, users and logs, block keys, never touch credentials"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_RoleTable |
| 400 | The request changes nothing, or the new name is taken | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Only proxy admins may change custom roles, and the license must include custom_roles | application/json ErrorDetail |
| 404 | No custom role has that role_id | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
role_id | string | Yes | Role Id |
role_name | string | Yes | Role Name |
description | string or null | No | Description |
base_role | string | Yes | Base Role |
permissions | array of string | No | Permissions |
denied_permissions | array of string | No | Denied Permissions |
created_by | string or null | No | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
DELETE /role/delete
Delete a custom role
Deletes a custom role. Each holder falls back to their Global Proxy Role, and the role row plus one row per holder are written to the audit log. Only proxy admins may call it, and it needs the custom_roles license feature.
Request body (application/json, schema DeleteRoleRequest):
| Field | Type | Required | Description |
|---|---|---|---|
role_id | string | Yes | Role Id |
Example request:
curl -X DELETE "http://localhost:4000/role/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"role_id": "8f6c2b1e-4d2a-4f7e-9b1c-2a3d4e5f6a7b"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json RoleDeleteResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Only proxy admins may change custom roles, and the license must include custom_roles | application/json ErrorDetail |
| 404 | No custom role has that role_id | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
role_id | string | Yes | The custom role that was deleted |
unassigned_users | integer | Yes | How many users lost the role and fell back to their Global Proxy Role |
POST /role/assign
Give a user a custom role
Gives a user a custom role, which takes effect on the user's next request. A proxy_admin user is refused with 400, because custom roles never restrict proxy admins. Only proxy admins may call it. It needs the custom_roles license feature, and the change is written to the audit log.
Request body (application/json, schema AssignRoleRequest):
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | User Id |
role_id | string | Yes | Role Id |
Example request:
curl -X POST "http://localhost:4000/role/assign" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user-123",
"role_id": "8f6c2b1e-4d2a-4f7e-9b1c-2a3d4e5f6a7b"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json _UserRoleRow |
| 400 | The user is a proxy admin, whom custom roles never restrict | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Only proxy admins may change custom roles, and the license must include custom_roles | application/json ErrorDetail |
| 404 | No custom role or no user has that id | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | User Id |
custom_role_id | string or null | No | Custom Role Id |
POST /role/unassign
Take a custom role away from a user
Removes a user's custom role so only their Global Proxy Role applies again. Only proxy admins may call it. It needs the custom_roles license feature, and the change is written to the audit log.
Request body (application/json, schema UnassignRoleRequest):
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | User Id |
Example request:
curl -X POST "http://localhost:4000/role/unassign" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user-123"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json _UserRoleRow |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Only proxy admins may change custom roles, and the license must include custom_roles | application/json ErrorDetail |
| 404 | No user has that user_id | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | User Id |
custom_role_id | string or null | No | Custom Role Id |