Add Members¶
POST /api/v1/workspace/{workspace_uuid}/member/batch_add
Overview¶
Add existing site accounts to a workspace in batches and assign them the same role.
Prerequisites and Usage Steps¶
Requires External credentials with w permission. First select existing accounts from the site account list, then select roles available in this workspace from the workspace role list. This API does not create accounts and does not send account creation emails. Accounts can be in normal or disabled status, but disabled accounts cannot log in normally and do not appear in this module's member list. Account UUIDs are deduplicated and then validated one by one; any invalid account or role causes an error first. Adding a direct member who has already joined the workspace normally reports a duplicate error and cannot be treated as an idempotent success. An empty account array or empty role array returns true directly after the existing validations complete without adding any relationships; clients should prevent unintentional empty operations. Ownership cannot be granted through batch add; use the transfer API for owners.
Route Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| workspace_uuid | string | Y | Target workspace UUID; first confirm the active status and site. Example: wksp_example001How to obtain or fill in: Obtain from content.data[].uuid in the workspace list and verify the workspace name. |
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 using the algorithm on this page. Example: v20240417How to obtain or fill in: The example on this page uses this fixed version, which pairs with the example signing algorithm. |
|
| X-Df-Access-Key | string | Y | Read APIs accept r or w credentials; write APIs require w credentials. Example: <external-access-key>How to obtain or fill in: Assigned by the site administrator as an External API AK; the workspace OpenAPI Key cannot be used. |
| X-Df-Signature | string | Y | Concatenate the uppercase method, nonce, original full path, timestamp, and original UTF-8 request body with spaces, then compute HMAC-SHA256 and take the hex digest. Example: <hmac-sha256-hex>How to obtain or fill in: Compute with the matching SK as described in External API Signature Authentication; see the complete runnable template below. |
| X-Df-Timestamp | string | Y | Must fall within the signature validity window configured for the site; do not reuse the example time. Example: 1785427200How to obtain or fill in: Generate the current Unix seconds string with str(int(time.time())) when sending. |
| X-Df-Nonce | string | Y | Temporary serial number; generate a new value and recompute the signature when resending after a failure. Example: 97d275ee9f774315a7885ba7347acbd9How to obtain or fill in: Regenerate with uuid.uuid4().hex for each request. |
Body Request Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| accountUUIDs[*] | string | A single account UUID; do not enter an email, account name, or workspace UUID. Example: acnt_example001How to obtain or fill in: Obtain existing members from content.data[].uuid in the workspace member list; for adding or transferring, you can also obtain the target account from the site account list. |
|
| roleUUIDs[*] | string | A single valid role UUID; use the actual identifier for built-in roles and the returned uuid for custom roles. Example: generalHow to obtain or fill in: Obtain the uuid of a valid role for the workspace from the workspace role list; common built-in roles are general, readOnly, and wsAdmin. |
|
| accountUUIDs | array | Y | Required string array; after deduplication, only existing accounts with status=0 or 2 are accepted; null is invalid, and [] adds nothing. Allows null: False Example: ["acnt_example001"]How to obtain or fill in: Obtain existing members from content.data[].uuid in the workspace member list; for adding or transferring, you can also obtain the target account from the site account list. |
| roleUUIDs | array | Y | Required string array; roles must be within the workspace's valid scope; multiple can be specified, but owner cannot be included. null is invalid, and [] adds nothing. Allows null: False Example: ["general"]How to obtain or fill in: Obtain the uuid of a valid role for the workspace from the workspace role list; common built-in roles are general, readOnly, and wsAdmin. |
Additional Parameter Notes¶
For authentication, see External API Signature Authentication. The example on this page uses v20240417, which pairs with the signing algorithm for the original full path, query, and request body. This module operates on membership or roles in a specified workspace and does not create accounts themselves. After a write request fails, verify the current membership and role state before deciding to retry. This operation adds direct member-role associations and updates existing invitation records; success does not return per-account status, so verify each item after a failure.
Request Example¶
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 address 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/workspace/wksp_example001/member/batch_add'
query = {}
data = {'accountUUIDs': ['acnt_example001'], 'roleUUIDs': ['general']}
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")) # Handle by errorCode, content, and traceId; do not output the AK/SK.
raise SystemExit(1)
except (URLError, TimeoutError):
print('The request result is unknown. First verify the target's current state and whether the write already happened, then decide whether to re-sign and retry; do not automatically repeat write requests.')
raise SystemExit(1)
print(json.dumps(payload, ensure_ascii=False, indent=2))
Response¶
HTTP 200 with the unified application/json envelope; business data is in content; External does not automatically add declaration, and list pagination keeps content.pageInfo.
| Field | Type | Description |
|---|---|---|
| content | boolean | true on success; not the number of items added; an empty operation may also return true. |
{
"code": 200,
"content": true,
"errorCode": "",
"message": "",
"success": true,
"traceId": "TRACE-EXAMPLE"
}
Error Responses¶
For authentication, rate limiting, and common request errors, see Common Error Definitions.
The table below lists verified business and request errors. Ordinary database/downstream 5xx errors or unhandled exceptions are wrapped globally as ft.InternalServerError; a failed write request does not guarantee that nothing partially took effect, so verify the current relationship state first.
| HTTP Status | errorCode | Trigger Condition | Message or Response Description | Handling |
|---|---|---|---|---|
| 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 | Invalid request JSON syntax | Request JSON format error | Fix the JSON according to content.reason, line, and column. |
| 400 | ft.JsonFormatError | The top level of the request JSON is not an object | Some json file format error | Submit a JSON object; do not use an array or null as the entire request body. |
| 400 | ft.InvalidAccountUUID | The deduplicated account list contains accounts that do not exist, are deleted, or are not in status 0/2 | Invalid account UUID: {} | Reselect valid uuids from the site account list. |
| 400 | ft.InvalidRoleUUID | roleUUIDs contains roles outside the workspace's valid scope | Invalid role UUID: {} | Use a valid uuid returned by that workspace's role list. |
| 400 | ft.ForbiddenBatchAddOwner | roleUUIDs in the actual add request contains owner | Invalid operation; owners cannot be added in batches | Add members with a regular role; when an Owner change is needed, use the transfer API. |
| 404 | ft.MemberAlreadyExistsInWorkspace | The account has status=0 and an active direct member association already exists in this workspace | These members already exist in the workspace | Check existing members first; use batch modification to update roles instead of adding again. |
| 401 | ft.WKSPNotExistOrReleased | When there are actual relationships to add, the workspace does not exist or is not active | Workspace does not exist or has been released | Select an active workspace from the workspace list. |
| 500 | ft.InternalServerError | Database, cache, cancellation of legacy approval jobs, or unhandled array/field exceptions | Internal error | Save the traceId and ask the administrator to verify the actual relationships and cache; the write may have partially committed and should not be blindly replayed. |