Skip to content

Create



POST /api/v1/role/add

Overview

Create a custom role in the current API Key workspace and save the permission set.

Before Calling and Usage Steps

First confirm the role name and the minimal required permissions, then submit name and a non-empty keys. desc can be omitted. Creation does not automatically bind members or API Keys to the role; subsequent interfaces such as member authorization use the returned uuid. The server deduplicates and expands optional permissions, and automatically adds routine.defaultAccess; the create response does not directly return the final permission list, so query permissions in the role details again. For historical wildcard groups such as workspace/cloudAccount/cloudBilling/rumApp, newly released administrator permissions are not automatically granted by old wildcard groups; you need to explicitly submit the corresponding leaf keys according to the optional scope. After a timeout, first check whether a role with the same name has already been created to avoid duplicate requests.

Request Headers

Parameter Name Type Required Description
DF-API-KEY string Y OpenAPI authentication credential of the workspace.
Example: <DF-API-KEY>
How to obtain or fill in: Obtain an OpenAPI Key with this operation permission from the API Key management of the target workspace.

Body Request Parameters

Parameter Name Type Required Description
keys[*] string A single permission key in the format group.permission, which must be within the optional scope of the current custom role. group.* can be expanded according to the allowed scope; explicitly submitting leaf permissions is preferred.
Example: anomaly.issueManage
How to obtain or fill in: Confirm in the role management of the console which permissions can currently be selected by custom roles; you can also refer to content.permissions in the role details of a similar custom role and select specific leaf keys as needed. Do not copy permissions exclusive to system roles.
name string Y Role name, required for both creation and modification, maximum 256 characters.
Null allowed: False
Maximum length: 256
Example: Incident Collaboration
How to obtain or fill in: First use the role list to check the roles visible in the current workspace, and choose a name that is not already taken.
desc string Optional description. If omitted on creation, it is an empty string; if omitted on modification, the original value is retained, and passing an empty string clears it. The runtime declaration length limit is 3000, but the current storage capacity is shorter, so it is recommended to keep it within 256 characters.
Null allowed: False
Empty string allowed: True
Maximum length: 3000
Example: Allows handling Incident issues.
How to obtain or fill in: Fill in according to the purpose of the role; it is recommended not to exceed 256 characters, consistent with the current storage capacity.
keys array Y Array of permission key strings. Required on creation; although modification declares it optional, at least one usable permission must actually be provided. Updates replace the old permissions entirely, not append.
Null allowed: False
Example: ["anomaly.issueManage"]
How to obtain or fill in: Confirm in the role management of the console which permissions can currently be selected by custom roles; you can also refer to content.permissions in the role details of a similar custom role and select specific leaf keys as needed. Do not copy permissions exclusive to system roles.

Additional Parameter Notes

After successful creation, verify the actual permissions through role details. The role list can be used for authorization processes such as the workspace member list.

Request Example

curl --request POST 'https://openapi.guance.com/api/v1/role/add' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"name":"Incident Collaboration","desc":"Allows handling Incident issues.","keys":["anomaly.issueManage"]}'

Response

HTTP 200, application/json. The example below shows the main fields that can be read directly.

Field Type Description
content.id integer or null Record ID; the value returned on creation is constructed before submission and may be null, so use uuid to operate on the resource.
content.uuid string The created role_ role UUID.
content.workspaceUUID string The workspace it belongs to.
content.name string Role name.
content.desc string Role description.
content.isSystem integer 0 for a created custom role.
content.builtinRoleUUID string Management built-in template UUID; empty for an ordinary self-built role.
content.isAllWorkspace integer Cross-workspace built-in template application flag; 0 for an ordinary self-built role.
content.status integer Record status, 0 on successful creation.
content.creator string Creator identity.
content.updator string Updater identity, initially an empty string.
content.createAt integer Creation time, in Unix seconds.
content.updateAt integer Update time, in Unix seconds, initially -1.
content.deleteAt integer Deletion time, in Unix seconds, -1 if not deleted.
content.declaration object or null Workspace public declaration.
{
  "code": 200,
  "content": {
    "id": null,
    "uuid": "role_example",
    "workspaceUUID": "wksp_example",
    "name": "Incident Collaboration",
    "desc": "Allows handling Incident issues.",
    "isSystem": 0,
    "builtinRoleUUID": "",
    "isAllWorkspace": 0,
    "status": 0,
    "creator": "wsak_example",
    "updator": "",
    "createAt": 1785430800,
    "updateAt": -1,
    "deleteAt": -1,
    "declaration": {}
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Response

For authentication, rate limiting, and common request errors, see Common Error Definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Handling Method
406 ft.ParameterValidationFailed A request field is missing, or a field value violates the declared validation conditions Parameter parsing failed Check the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError The request JSON syntax is invalid Request JSON format error Fix the JSON according to content.reason, line, and column.
400 ft.JsonFormatError The JSON top level is not an object Some json file format error Submit a single JSON object.
406 ft.RolePermissionFormatInvalid keys is omitted, empty, contains no valid permission, or a permission is not in group.permission format Role permission format error Submit at least one currently selectable permission key; each item uses two dot-separated segments.
406 ft.RolePermissionInvalid The permission group or sub-permission is not in the currently selectable set for custom roles Role permission invalid Reselect from the selectable scope in the console or from the permission details of a similar custom role.
400 ft.RoleNameExists A role with the same name exists in the scope visible to the current workspace Role name {} already exists Use a name that is not already taken.
500 ft.InternalServerError Saving, permission refresh, or other internal processing failed Internal error First query the role details to confirm the saved name and permissions, then decide whether to retry; if the failure persists, provide the traceId.

Feedback

Is this page helpful?