Skip to main content

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.

MethodPathSummary
GET/role/permissionsThe permission catalogue for custom roles
GET/role/listList custom roles
GET/role/infoGet a custom role with its user count
POST/role/newCreate a custom role
POST/role/updateUpdate a custom role
DELETE/role/deleteDelete a custom role
POST/role/assignGive a user a custom role
POST/role/unassignTake 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:

StatusDescriptionBody
200Successful Responseapplication/json PermissionCatalogueResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a proxy admin or admin viewer, or the license does not include custom_rolesapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
permissionsarray of PermissionInfoYesPermissions
wildcardstringYesWildcard
assignable_base_rolesarray of stringYesAssignable 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:

StatusDescriptionBody
200Successful Responseapplication/json array of Spanway_RoleTable
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a proxy admin or admin viewer, or the license does not include custom_rolesapplication/json ErrorDetail
500The database is not connectedapplication/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:

NameInTypeRequiredDescription
role_idquerystringYes

Example request:

curl -X GET "http://localhost:4000/role/info?role_id=role_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json RoleInfoResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a proxy admin or admin viewer, or the license does not include custom_rolesapplication/json ErrorDetail
404No custom role has that role_idapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
role_idstringYesRole Id
role_namestringYesRole Name
descriptionstring or nullNoDescription
base_rolestringYesBase Role
permissionsarray of stringNoPermissions
denied_permissionsarray of stringNoDenied Permissions
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At
assigned_user_countintegerYesAssigned 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):

FieldTypeRequiredDescription
role_namestringYesRole Name
descriptionstring or nullNoDescription
base_rolestringYesBase Role
permissionsarray of stringNoPermissions
denied_permissionsarray of stringNoDenied 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:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_RoleTable
400Another custom role already has that nameapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admins may change custom roles, and the license must include custom_rolesapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
role_idstringYesRole Id
role_namestringYesRole Name
descriptionstring or nullNoDescription
base_rolestringYesBase Role
permissionsarray of stringNoPermissions
denied_permissionsarray of stringNoDenied Permissions
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated 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):

FieldTypeRequiredDescription
role_idstringYesRole Id
role_namestring or nullNoRole Name
descriptionstring or nullNoDescription
base_rolestring or nullNoBase Role
permissionsarray of string or nullNoPermissions
denied_permissionsarray of string or nullNoDenied 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:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_RoleTable
400The request changes nothing, or the new name is takenapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admins may change custom roles, and the license must include custom_rolesapplication/json ErrorDetail
404No custom role has that role_idapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
role_idstringYesRole Id
role_namestringYesRole Name
descriptionstring or nullNoDescription
base_rolestringYesBase Role
permissionsarray of stringNoPermissions
denied_permissionsarray of stringNoDenied Permissions
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated 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):

FieldTypeRequiredDescription
role_idstringYesRole 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:

StatusDescriptionBody
200Successful Responseapplication/json RoleDeleteResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admins may change custom roles, and the license must include custom_rolesapplication/json ErrorDetail
404No custom role has that role_idapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
role_idstringYesThe custom role that was deleted
unassigned_usersintegerYesHow 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):

FieldTypeRequiredDescription
user_idstringYesUser Id
role_idstringYesRole 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:

StatusDescriptionBody
200Successful Responseapplication/json _UserRoleRow
400The user is a proxy admin, whom custom roles never restrictapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admins may change custom roles, and the license must include custom_rolesapplication/json ErrorDetail
404No custom role or no user has that idapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
user_idstringYesUser Id
custom_role_idstring or nullNoCustom 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):

FieldTypeRequiredDescription
user_idstringYesUser 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:

StatusDescriptionBody
200Successful Responseapplication/json _UserRoleRow
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admins may change custom roles, and the license must include custom_rolesapplication/json ErrorDetail
404No user has that user_idapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
user_idstringYesUser Id
custom_role_idstring or nullNoCustom Role Id