Create data resources (recommended, key points)
This document is automatically generated based on https://github.com/authing/authing-docs-factory based on https://api-explorer.genauth.ai V3 API, and is consistent with API parameters and return results. If the description of this document is incorrect, please refer to V3 API.
Description
This interface is used to create data resources. When you have data that needs to be set with permissions, create data resources of the corresponding type according to their data types. Currently, we support three types: string, array, and tree.
Note
The struct field in the request body needs to pass in different data structures according to different resource types. Please refer to the following examples for details
Request example
Example of creating a string type data resource
This type can be used when your data can be represented by only one string, such as an API, a user ID, etc.
The following is an example of creating a data resource representing the '/resource/create' API:
{
"namespaceCode": "examplePermissionNamespace",
"resourceName": "createResource API",
"description": "This is the createResource API",
"resourceCode": "createResourceAPI",
"type": "STRING",
"struct": "/resource/create",
"actions": ["access"]
}Example of creating an array type data resource
This type can be used when your data is a group of data of the same type, such as a group of document links, a group of access card numbers, etc. The following is an example of creating a data resource representing a set of access card numbers:
{
"namespaceCode": "examplePermissionNamespace",
"resourceName": "A set of access card numbers",
"description": "This is a set of access card numbers",
"resourceCode": "accessCardNumber",
"type": "ARRAY",
"struct": ["accessCardNumber1", "accessCardNumber2", "accessCardNumber3"],
"actions": ["get", "update"]
}Example of creating a tree type data resource
This type can be used when your data has a hierarchical relationship, such as organizational structure, folder structure, etc. The following is an example of creating a data resource representing a company's organizational structure:
{
"namespaceCode": "examplePermissionNamespace",
"resourceName": "GenAuth",
"description": "This is the organizational structure of GenAuth",
"resourceCode": "authing",
"type": "TREE",
"struct": [
{
"name": "Product",
"code": "product",
"value": "product",
"children": [
{
"name": "Product Manager",
"code": "productManager",
"value": "pm"
},
{
"name": "Design",
"code": "design",
"value": "ui"
}
]
},
{
"name": "R&D",
"code": "researchAndDevelopment",
"value": "rd"
}
],
"actions": ["get", "update", "delete"]
}Method name
ManagementClient.createDataResource
Request parameters
| Name | Type | Required | Default value | Description | Sample value |
|---|---|---|---|---|---|
| actions | string[] | Yes | - | Data resource permission operation list Array length limit: 50. | ["read","get"] |
| struct | Yes | - | Data resource structure, supports string (STRING), tree structure (TREE) and array structure (ARRAY). | ||
| type | string | yes | - | Data resource type, currently supports tree structure (TREE), string (STRING), array (ARRAY) | TREE |
| resourceCode | string | yes | - | Data resource Code, unique in the permission space | dataResourceTestCode |
| resourceName | string | yes | - | Data resource name, unique in the permission space | example data resource name |
| namespaceCode | string | yes | - | Permission space Code to which the data resource belongs | examplePermissionNamespace |
| description | string | no | - | Data resource description | example data resource description |
Sample code
import { ManagementClient, Models } from "authing-node-sdk";
// Initialize ManagementClient
const managementClient = new ManagementClient({
// Need to be replaced with your GenAuth Access Key ID
accessKeyId: "GEN_AUTH_ACCESS_KEY_ID",
// Need to be replaced with your GenAuth Access Key Secret
accessKeySecret: "GEN_AUTH_ACCESS_KEY_SECRET",
// If it is a private deployment customer, you need to set the GenAuth service domain name
// host: 'https://api.your-authing-service.com'
});
(async () => {
const result = await managementClient.createDataResource({
namespaceCode: "examplePermissionNamespace",
resourceCode: "treeResourceCode",
resourceName: "Example Tree Data Resource",
type: CreateDataResourceDto.type.TREE,
struct: [
{
code: "tree1",
name: "Tree Node 1",
value: "Tree Node 1 Description",
children: [
{
code: "tree11",
name: "Tree Node 11",
value: "Tree Node 11 Description",
},
],
},
{
code: "tree2",
name: "Tree Node 2",
value: "Tree Node 2 Description",
},
],
description: "Example tree data resource description",
actions: ["get", "read"],
});
console.log(JSON.stringify(result, null, 2));
})();Request response
Type: CreateDataResourceResponseDto
| Name | Type | Description |
|---|---|---|
| statusCode | number | Business status code, which can be used to determine whether the operation is successful. 200 means success. |
| message | string | Description |
| apiCode | number | Segmented error code, which can be used to get the specific error type (successful request does not return). For a detailed list of error codes, see: API Code List |
| requestId | string | Request ID. Returned when the request fails. |
| data | <a CreateDataResourceRespDto | Response data |
Sample result:
{
"statusCode": 200,
"message": "Operation successful",
"requestId": "934108e5-9fbf-4d24-8da1-c330328abd6c",
"data": {
"resourceName": "Sample data resource name",
"resourceCode": "dataResourceTestCode",
"type": "TREE",
"description": "Sample data resource description",
"actions": "[\"read\",\"get\"]"
}
}Data structure
CreateDataResourceRespDto
| Name | Type | Is it required? | Description | Sample value |
|---|---|---|---|---|
| resourceName | string | Yes | Data resource name, unique in the permission space | Sample data resource name |
| resourceCode | string | Yes | Data resource Code, unique in the permission space | dataResourceTestCode |
| type | string | Yes | Data resource type, currently supports tree structure (TREE), string (STRING), array (ARRAY) | TREE |
| description | string | No | Data resource description | Sample data resource description |
| struct | Yes | Data resource structure, supports string (STRING), tree structure (TREE) and array structure (ARRAY). | ||
| actions | array | Yes | Data resource permission operation list. Array length limit: 50. | ["read","get"] |