Create Member Group¶
POST /api/v1/mgroup/add
Overview¶
Create a backend group and set initial account members.
Before Calling and Usage Steps¶
First query for groups with the same name, and select existing accounts as initial members. This endpoint deduplicates by name but has no idempotency key; after a timeout, query the list first to confirm the result. accountUUIDs only establishes group relationships; it does not create or activate accounts. Although it declares that it accepts refWorkspaces, the current create implementation does not save workspace/role mappings; omit this parameter and call Modify Workspace Roles after obtaining the new uuid. The response is only a snapshot of the group entity, with no member or role lists.
Request Headers¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| X-Df-SVersion | string | Signature version for the original path and request body; you cannot omit it and continue to use the algorithm on this page. Example: v20240417How to obtain or fill it in: The example on this page uses this fixed version, which pairs with the example signing algorithm. |
|
| X-Df-Access-Key | string | Y | Read endpoints can use r or w credentials; write endpoints require w credentials. Example: <external-access-key>How to obtain or fill it in: Assigned by the site administrator as an External API AK; do not use a Workspace OpenAPI Key. |
| X-Df-Signature | string | Y | Concatenate the uppercased method, nonce, original full path, timestamp, and raw UTF-8 request body with spaces, then compute HMAC-SHA256 and take the hex digest. Example: <hmac-sha256-hex>How to obtain or fill it in: Compute it with the matching SK as described in External API Signature Authentication; see the complete runnable template below. |
| X-Df-Timestamp | string | Y | Must be within the signature validity window configured for the site; do not reuse the example timestamp. Example: 1785427200How to obtain or fill it in: When sending, use str(int(time.time())) to generate the current Unix seconds string. |
| X-Df-Nonce | string | Y | Temporary nonce; when resending after a failure, also generate a new value and recompute the signature. Example: 97d275ee9f774315a7885ba7347acbd9How to obtain or fill it in: Regenerate uuid.uuid4().hex for each request. |
Body Request Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| accountUUIDs[*] | string | A single account UUID string, not an email address or workspace UUID. Example: acnt_example001How to obtain or fill it in: Obtain a single account from content.data[].uuid in the Site Account List. |
|
| refWorkspaces[*].roleUUIDs[*] | string | A single role UUID string; do not use a number or object. Do not rely solely on a successful response to determine that the role is actually valid. Example: readOnlyHow to obtain or fill it in: Obtain the role uuid from the Workspace Role List for the corresponding workspace, and select it according to the platform authorization policy. |
|
| name | string | Y | Required non-empty name, up to 256 characters. Allows null: False Maximum length: 256 Example: 示例研发分组How to obtain or fill it in: Check active group names in the Backend Group List, then specify a new non-empty name. |
| accountUUIDs | array | Complete array of account UUIDs, deduplicated as a set; the caller must pre-validate that accounts exist and have the required state. The endpoint does not actively filter out all unknown or deleted accounts. Omitting it, null, or [] adds no initial members. Allows null: True Example: ["acnt_example001"]How to obtain or fill it in: Obtain real accounts from content.data[].uuid in the Site Account List, and verify their status first. |
|
| refWorkspaces | array | The current create endpoint does not save this parameter; omit it and call Modify Workspace Roles separately after creation. Allows null: True Example: [{"workspaceUUID": "wksp_example001", "roleUUIDs": ["readOnly"]}]How to obtain or fill it in: Obtain the workspace UUID from the Workspace List, then obtain that workspace's roles from the Workspace Role List for each workspace. |
|
| refWorkspaces[*] | object | A workspace authorization object; when its fields appear in the request, they must still conform to the declared structure. This object is not applied during creation. Example: {"workspaceUUID": "wksp_example001", "roleUUIDs": ["readOnly"]}How to obtain or fill it in: For each target workspace, provide one workspaceUUID and a complete roleUUIDs array; provide each workspace only once. |
|
| refWorkspaces[*].workspaceUUID | string | Conditionally required | Required workspace UUID string. This mapping is currently ignored during creation. Allows null: False Example: wksp_example001How to obtain or fill it in: Obtain active workspaces that need to be authorized through the backend group from the Workspace List. |
| refWorkspaces[*].roleUUIDs | array | Conditionally required | Required complete role array. This mapping is currently ignored during creation. Allows null: False Example: ["readOnly"]How to obtain or fill it in: Obtain the corresponding valid role UUIDs from the Workspace Role List based on this item's workspaceUUID. |
Additional Parameter Notes¶
Use site-level External API AK/SK. For the signing method, see External API Signature Authentication. Backend groups with the mgroup_ prefix can be associated with multiple workspaces and grant inherited roles; they are not the same type of object as group_ teams within a single workspace. Write requests require w permission, while list requests can use r or w. The repository countLimit defaults to 1000 and can be overridden per site; the current logic rejects a request only when the existing count is greater than the threshold, so do not treat an equal count as a request that the backend will definitely reject. The create snapshot is obtained before flush, and id may be null.
Example Request¶
import hashlib
import hmac
import json
import time
import uuid
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
# Replace with the target site URL and the External API AK/SK assigned by the administrator.
server = "https://external-api.guance.com"
access_key = "<external-access-key>"
secret_key = "<external-secret-key>"
method = 'POST'
path = '/api/v1/mgroup/add'
query = {}
data = {'name': '示例研发分组', 'accountUUIDs': ['acnt_example001']}
full_path = path + ("?" + urlencode(query) if query else "")
body = "" if data is None else json.dumps(data, ensure_ascii=False, separators=(",", ":"))
timestamp = str(int(time.time()))
nonce = uuid.uuid4().hex
string_to_sign = " ".join([method, nonce, full_path, timestamp, body])
signature = hmac.new(secret_key.encode("utf-8"), string_to_sign.encode("utf-8"), hashlib.sha256).hexdigest()
headers = {
"X-Df-Access-Key": access_key,
"X-Df-Timestamp": timestamp,
"X-Df-Nonce": nonce,
"X-Df-Signature": signature,
"X-Df-SVersion": "v20240417",
}
if data is not None:
headers["Content-Type"] = "application/json"
request = Request(server + full_path, data=None if data is None else body.encode("utf-8"), headers=headers, method=method)
try:
with urlopen(request, timeout=30) as result:
payload = json.loads(result.read().decode("utf-8"))
except HTTPError as error:
print("HTTP", error.code, error.read().decode("utf-8")) # Check errorCode, content, and traceId; do not output the AK/SK.
raise SystemExit(1)
except (URLError, TimeoutError):
print('请求结果未知,请先查询实际配置及任务状态,再决定是否重试写请求。')
raise SystemExit(1)
print(json.dumps(payload, ensure_ascii=False, indent=2))
Response¶
HTTP 200 with the standard External application/json envelope; declaration is not added automatically. content is a snapshot of the new group entity and does not include member or role relationship lists.
| Field | Type | Description |
|---|---|---|
| content.id | integer or null | Record sequence number; calls use uuid. The create snapshot is obtained before flush, so id may be null. |
| content.uuid | string | Backend group UUID, usually with the mgroup_ prefix. |
| content.status | integer | Active groups are 0; the list filters out deleted groups. |
| content.creator | string | Creator identity; for External it is usually sys. |
| content.updator | string | Identity of the most recent modification; it may be empty if the group has not been modified. |
| content.createAt | integer | Creation time in Unix seconds. |
| content.deleteAt | integer | Deletion time in Unix seconds; usually -1 if not deleted. |
| content.updateAt | integer | Group entity update time; usually -1 if not yet modified. Changing only members/workspace roles does not guarantee that the entity time is updated synchronously, so do not use it to determine whether authorization has changed. |
| content.name | string | Display name of the backend group. |
{
"code": 200,
"content": {
"id": null,
"uuid": "mgroup_example001",
"status": 0,
"creator": "sys",
"updator": "",
"createAt": 1785427200,
"deleteAt": -1,
"updateAt": -1,
"name": "示例研发分组"
},
"errorCode": "",
"message": "",
"success": true,
"traceId": "TRACE-EXAMPLE"
}
Error Responses¶
For authentication, rate limiting, and common request errors, see Common Error Definitions.
The table lists verified request and business errors; ordinary internal exceptions ultimately become 500 ft.InternalServerError. The group/relationship may have been committed while a subsequent cache or audit operation failed; read the current state first and do not infer that the change did not take effect solely from the error.
| HTTP Status | errorCode | Trigger Condition | Message or Response Description | Resolution |
|---|---|---|---|---|
| 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 top level of the JSON is not an object | JSON file format error in some cases | Submit a JSON object as described in the table. |
| 406 | ft.MissingParameters | name is an empty string | Parameter missing | Provide a non-empty group name. |
| 400 | ft.MGroupNameExists | An active backend group with the same name already exists | A group with the same name already exists | Query the list first and choose a name that is not duplicated; modify the existing group instead of creating it again. |
| 400 | ft.MGroupCountExceedsLimit | Creating another group when the current number of active groups is greater than the site countLimit | The number of groups exceeds the maximum limit. Maximum limit: {} |
Ask the administrator to check the site group quota and existing groups, then clean up or adjust the configuration before creating again. |
| 500 | ft.InternalServerError | Database, audit, or unhandled field exception; the group may already have been saved | Internal error | Save the traceId and confirm by name in the list whether it has been created; if it already exists, reuse that uuid and do not blindly create it again. |