List¶
GET /api/v1/workspace/{workspace_uuid}/role/list
Overview¶
List the roles of the target workspace with pagination.
Prerequisites and Usage Steps¶
Specify the workspace UUID. The list includes system built-in, management backend built-in, and workspace custom roles that apply to the workspace. To find a specific role, filter by name and read the uuid as the stable identifier.
The example uses External API signature version v20240417. Set the External API URL, Access Key, and Secret Key of the target site to DF_EXTERNAL_API_URL, DF_EXTERNAL_ACCESS_KEY, and DF_EXTERNAL_SECRET_KEY respectively. Replace the example IDs with actual values.
Path Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| workspace_uuid | string | Y | UUID of the target workspace. Example: wksp_exampleHow to obtain or fill in: Get it from content.data[].uuid in the response of Workspace List and use the original value. |
Request Headers¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| X-Df-SVersion | string | Signature version; the examples below use v20240417. Example: v20240417How to obtain or fill in: Fill in as shown in the example, matching the signature algorithm. |
|
| X-Df-Access-Key | string | Y | Request AK information Example: <access-key>How to obtain or fill in: Assigned by the External API administrator. |
| X-Df-Signature | string | Y | Signature information Example: <hex-signature>How to obtain or fill in: Use the Secret Key to compute HMAC-SHA256 over the text consisting of GET, nonce, request path and raw query string, timestamp, and an empty string, then take the hexadecimal result. |
| X-Df-Timestamp | string | Y | Timestamp of the request Example: 1785456000How to obtain or fill in: Fill in the current Unix seconds at call time, for example by running date +%s. |
| X-Df-Nonce | string | Y | Temporary code generated for the request Example: b53b47e12e514616ad8cb1f17cb66dceHow to obtain or fill in: Generate a new random value for each request, for example uuid.uuid4().hex. |
Query Request Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| search | string | Fuzzy match by name; omit it or pass a blank value to not filter by name. Allows null: False Example: 只读How to obtain or fill in: Use the role name or part of it as seen on the role management page in the console. |
|
| statMember | boolean | Only when lowercase true is passed, count members and add memberCount to each role. Not counted by default. Allows null: False Example: trueHow to obtain or fill in: Set the URL query parameter statMember=true when you need to display the number of role members. |
|
| pageSize | integer | Number of records per page, default 100. Pass a positive integer. Allows null: False Example: 100How to obtain or fill in: Fill in an integer according to the page capacity required by the client. |
|
| pageIndex | integer | Page number, default 1. Allows null: False Example: 1How to obtain or fill in: Increase from 1 page by page, and verify with the page number in the response. |
Additional Parameter Notes¶
Use the External API signature credentials assigned to the current target site.
Request Example¶
import hmac
import os
import time
import uuid
from urllib.parse import urlencode
import requests
server = os.environ["DF_EXTERNAL_API_URL"].rstrip("/")
path = "/api/v1/workspace/wksp_example/role/list"
query = {'search': '只读', 'statMember': 'true', 'pageIndex': 1}
if query:
path += "?" + urlencode(query)
timestamp = str(int(time.time()))
nonce = uuid.uuid4().hex
payload = " ".join(("GET", nonce, path, timestamp, ""))
signature = hmac.digest(os.environ["DF_EXTERNAL_SECRET_KEY"].encode(), payload.encode(), "sha256").hex()
headers = {
"X-Df-Access-Key": os.environ["DF_EXTERNAL_ACCESS_KEY"],
"X-Df-Timestamp": timestamp,
"X-Df-Nonce": nonce,
"X-Df-SVersion": "v20240417",
"X-Df-Signature": signature,
}
try:
result = requests.get(server + path, headers=headers, timeout=15)
except requests.RequestException:
print('读取失败,可退避后重新签名重试,保留traceId及查询条件。')
raise SystemExit(1)
if not 200 <= result.status_code < 300:
print("HTTP", result.status_code, result.text) # Keep errorCode, content, and traceId; do not output AK/SK.
raise SystemExit(1)
data = result.json()["content"]
Response¶
HTTP 200, application/json.
| Field | Type | Description |
|---|---|---|
| content.data | array<object> |
Results on this page; an empty array when there are no records. |
| content.data[].id | integer | Role record ID. |
| content.data[].uuid | string | Role UUID. Use this field in other APIs that require a role identifier. |
| content.data[].name | string | Role name. |
| content.data[].desc | string | Role description. |
| content.data[].isSystem | integer | 1 indicates a system built-in role; 0 indicates other roles. |
| content.data[].workspaceUUID | string | The workspace that the role belongs to or applies to; can be empty for system built-in roles. |
| content.data[].builtinRoleUUID | string | UUID of the management backend built-in role template; empty when there is no template. |
| content.data[].isAllWorkspace | integer | Whether the management backend built-in role applies to all workspaces: 0 for no, 1 for yes. |
| content.data[].isManageBuiltinRole | boolean | Whether this is a built-in role defined and applied through the management backend. |
| content.data[].creator | string | Creator identifier. |
| content.data[].updator | string | Identifier of the last updater. |
| content.data[].createAt | integer | Creation time. Unix seconds. |
| content.data[].updateAt | integer | Last update time, in Unix seconds; can be -1 when it has not occurred. |
| content.data[].deleteAt | integer | Deletion time, in Unix seconds; -1 when not deleted. |
| content.data[].status | integer | Role record status. |
| content.data[].creatorInfo | object | Creator profile; {} when it cannot be found. |
| content.data[].updatorInfo | object | Last updater profile; {} when it cannot be found. |
| content.data[].memberCount | integer | Returned only when statMember=true. Deduplicated by member, including members who are granted the role directly and those who obtain it through a group. |
| content.pageInfo | object | Pagination information. |
| content.pageInfo.pageIndex | integer | Current page number, starting from 1. |
| content.pageInfo.pageSize | integer | Number of records per page. |
| content.pageInfo.count | integer | Number of records returned on the current page. |
| content.pageInfo.totalCount | integer | Total number of roles matching the conditions, used to calculate the total number of pages. |
{
"code": 200,
"content": {
"data": [
{
"id": 101,
"uuid": "role_example",
"name": "日志只读",
"desc": "查询应用日志",
"isSystem": 0,
"workspaceUUID": "wksp_example",
"builtinRoleUUID": "",
"isAllWorkspace": 0,
"isManageBuiltinRole": false,
"status": 0,
"creatorInfo": {},
"updatorInfo": {},
"memberCount": 2
}
],
"pageInfo": {
"pageIndex": 1,
"pageSize": 100,
"count": 1,
"totalCount": 1
}
},
"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 | Resolution |
|---|---|---|---|---|
| 406 | ft.ParameterValidationFailed | An undeclared Query parameter is passed | The message indicates the invalid parameter. | Remove the fields not listed in the parameter table. |