Create¶
POST /api/v1/workspace/accesskey/add
Overview¶
Create an API Key for the current Workspace and bind it to read/manage roles.
Prerequisites and Usage Steps¶
Use an OpenAPI Key that has the workspace.openAPIKeyManage permission in the current Workspace. The route declaration specifies a freeEdition version limit, but the current OpenAPI authentication chain does not perform this version check; do not describe the version itself as necessarily resulting in 403. Check availability against the deployment and actual permissions. The resource scope always comes from the Workspace to which the request header Key belongs; you cannot use Body to switch Workspaces. An owner Key also requires the current identity to include owner; API management permission itself does not replace this check.
First select the least-privileged role required from the role list, then check the names of existing non-deleted Keys, and submit name, remark, and complete roleUUIDs. Omitting roleUUIDs defaults to ["wsAdmin"], which is not read-only. An explicit [] only means that no role association is written, and the response has roleInfo=[]. When the current authentication chain has no valid role association, it still falls back to ["wsAdmin"]; you cannot use [] to create a zero-permission Key or revoke permissions. For least privilege, explicitly bind readOnly or a verified custom role. The regular branch verifies item by item that roles are available in the current Workspace and have status=0.
Historical descriptions say owner is not included, but the current implementation has an owner compatibility branch: if the array contains owner, only an owner Key is created, other roles are ignored, and the remaining elements are not verified item by item. This requires the current owner identity, and each Workspace allows only one non-system, non-deleted owner Key (including disabled ones). Do not mix owner into a regular role array.
Create and rotation responses contain ak/sk plaintext; immediately write them to controlled credential storage. The OpenAPI authentication header uses the Key value (for example, the returned sk), not the wsak_ resource UUID. Subsequent list/detail results are affected by the calling identity, whether the target is manual/account-bound, and whether it is the current Key; they may be masked. Do not rely on subsequent reads to recover lost credentials, and do not claim that the current service implementation will never again return plaintext to any identity.
This operation is not idempotent; a duplicate-name error does not replace the old Key. It returns only after the database commit succeeds; on an error/network interruption, first query the list to confirm the name and UUID, then decide whether to create, to avoid duplicate credentials.
Request Headers¶
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| DF-API-KEY | string | Y | OpenAPI authentication credential for the Workspace. Example: <DF-API-KEY>How to obtain or enter: Obtain an OpenAPI Key with this operation permission from API Key Management in the target Workspace. |
Body Request Parameters¶
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| roleUUIDs[*] | string | A single valid role UUID; only an owner identity can create an owner Key. In the regular role branch, unknown/disabled/cross-Workspace roles are rejected. Example: readOnlyHow to obtain or enter: Use the uuid returned by the Role List, not the name. |
|
| name | string | Y | Required string; callers should provide a non-empty value, but the current declaration does not enforce non-emptiness. The storage column is 512 characters; keeping it to 512 or fewer is recommended. Whitespace is not trimmed automatically. Null allowed: False Example: automation_readerHow to obtain or enter: Define the name by purpose and check for duplicate names in the API Key List. |
| remark | string | Optional string, maximum 512 characters; if omitted, it is empty and cannot be null. Null allowed: False Maximum length: 512 Example: 仅读自动化How to obtain or enter: Record the purpose, responsible person, and update method; do not store credentials. |
|
| roleUUIDs | array | Optional complete role UUID array; if omitted, ["wsAdmin"]; [] only means that no association is written, authentication still falls back to wsAdmin, and it cannot be used to revoke permissions; each item is a string. null is not supported. If it contains owner, the special compatibility branch is used; see the usage notes. Null allowed: False Example: ["readOnly"]How to obtain or enter: Obtain roles available in the current Workspace from content.data[].uuid in the Role List. The built-in readOnly/wsAdmin/general are also role UUIDs. |
Additional Parameter Notes¶
This endpoint creates a manual Key in the current Workspace; explicitly set the required role. Omitting roleUUIDs uses wsAdmin.
Request Example¶
curl --request POST 'https://openapi.guance.com/api/v1/workspace/accesskey/add' \
-H 'DF-API-KEY: <DF-API-KEY>' \
-H 'Content-Type: application/json' \
--data-raw '{"name":"automation_reader","remark":"仅读自动化","roleUUIDs":["readOnly"]}'
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 | Database ID; in create responses, this is a pre-commit snapshot and may be null; subsequent operations use uuid. |
| content.uuid | string | API Key resource UUID starting with wsak_, used in details/delete/rotation paths; not the DF-API-KEY value. |
| content.workspaceUUID | string | UUID of the Workspace to which the current calling Key belongs. |
| content.name | string | Key name. |
| content.ak | string | Newly generated ak plaintext; not the resource uuid. Use it according to the credential conventions of the calling service. |
| content.sk | string | Newly generated sk plaintext, which can be used as the OpenAPI DF-API-KEY; save it securely immediately and do not write it to logs. |
| content.accountUUID | string | Bound account UUID; this endpoint creates it as "" and does not create account-bound credentials. |
| content.createdWay | string | Creation source; manual for this endpoint. |
| content.businessType | string | Compatible business category; an empty string for regular manual Keys. |
| content.isSystem | integer or boolean | System built-in flag; 0/false for regular manual Keys. |
| content.isOwnerRole | integer or boolean | Whether this is an owner Key; 0 for regular role creation and 1 for the owner compatibility branch. |
| content.remark | string | Remarks; default empty string. |
| content.isBurnAfterReading | integer or boolean | Historical display flag; 0 for regular creation. Do not infer from this that all subsequent reads will never return plaintext. |
| content.callCount | integer or null | Total call count; the create snapshot may be null before database default values are populated. Rotation does not reset historical statistics. |
| content.lastCallAt | integer or null | Most recent call time in Unix seconds; usually -1 when not recorded. The create snapshot may be null; rotation does not reset it. |
| content.status | integer | 0 normal; 3 after deletion; successful creation/rotation returns 0. |
| content.creator | string | Creator identity UUID. |
| content.updator | string | Last modifying identity; usually an empty string for creation. |
| content.createAt | integer | Creation time in Unix seconds; rotation retains the original creation time. |
| content.updateAt | integer | Last update time in Unix seconds; -1 if not updated after creation. |
| content.deleteAt | integer | Deletion time in Unix seconds; -1 if not deleted. |
| content.roleInfo | array<object> |
Role summary array; the regular branch contains the queried valid roles, and the owner branch contains only owner. When created with an explicit [], this can be [], but authentication still falls back to wsAdmin; do not conclude from this that permissions are zero. The complete role permission tree is not returned. |
| content.roleInfo[].uuid | string | Role UUID, such as readOnly/wsAdmin/owner or a custom role UUID in this Workspace. |
| content.roleInfo[].name | string | Role display name; do not use the display name in place of uuid. |
| content.declaration | object | Public declaration of the current Workspace. |
{
"code": 200,
"content": {
"id": null,
"uuid": "wsak_example",
"workspaceUUID": "wksp_example",
"name": "automation_reader",
"ak": "<NEW-AK>",
"sk": "<NEW-SK>",
"accountUUID": "",
"createdWay": "manual",
"businessType": "",
"isSystem": 0,
"isOwnerRole": 0,
"remark": "仅读自动化",
"isBurnAfterReading": 0,
"callCount": null,
"lastCallAt": null,
"status": 0,
"creator": "wsak_caller",
"updator": "",
"createAt": 1785427200,
"updateAt": -1,
"deleteAt": -1,
"roleInfo": [
{
"uuid": "readOnly",
"name": "Read-only"
}
],
"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 |
|---|---|---|---|---|
| 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 | Correct the JSON according to content.reason, line, and column. |
| 400 | ft.JsonFormatError | The top level of the request JSON is not an object | Partial JSON file format error | Provide a JSON object as shown in the example. |
| 400 | ft.AKNameRepeat | A non-system, non-deleted Key with the same name already exists in this Workspace, including disabled Keys | An AK with the same name already exists | Use the list to check whether it has already been created; if a new Key is truly needed, use a unique name. |
| 400 | ft.AKOnwerRepeat | The request contains owner, but the Workspace already has a non-system, non-deleted owner Key | An owner AK already exists | Use the controlled rotation process for the existing owner Key; do not create it again. |
| 400 | ft.InvalidRoleUUID | In the regular branch, a role is invalid/not authorized for this Workspace/disabled or deleted | Invalid role UUID: {} | Reselect a valid uuid from the current Workspace's role list. |
| 403 | ft.Forbidden | Insufficient API permissions, or a non-owner identity requests an owner Key | You do not have permission to perform this operation | Use a management Key that meets the requirements, preferably with a least-privilege role. |
| 401 | ft.WKSPNotExistOrReleased | The current Workspace does not exist or is inactive during refresh | Workspace does not exist or has been released | Confirm that the target Workspace is still active, and do not reuse management Keys across Workspaces. |
| 500 | ft.InternalServerError | Database or credential cache invalidation fails; rotation/deletion may have been committed before the error is returned | Internal error | First, use another valid management Key to read the original UUID and status. If the rotation response is lost and the old Key has become invalid, use another valid management Key to rotate again and securely receive the new credentials; do not repeatedly retry with the invalid old Key. |