Skip to content

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:

json
{
  "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:

json
{
  "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:

json
{
  "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

NameTypeRequiredDefault valueDescriptionSample value
actionsstring[]Yes-Data resource permission operation list Array length limit: 50.["read","get"]
structYes-Data resource structure, supports string (STRING), tree structure (TREE) and array structure (ARRAY).
typestringyes-Data resource type, currently supports tree structure (TREE), string (STRING), array (ARRAY)TREE
resourceCodestringyes-Data resource Code, unique in the permission spacedataResourceTestCode
resourceNamestringyes-Data resource name, unique in the permission spaceexample data resource name
namespaceCodestringyes-Permission space Code to which the data resource belongsexamplePermissionNamespace
descriptionstringno-Data resource descriptionexample data resource description

Sample code

ts
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

NameTypeDescription
statusCodenumberBusiness status code, which can be used to determine whether the operation is successful. 200 means success.
messagestringDescription
apiCodenumberSegmented 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
requestIdstringRequest ID. Returned when the request fails.
data<a CreateDataResourceRespDtoResponse data

Sample result:

json
{
  "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

NameTypeIs it required?DescriptionSample value
resourceNamestringYesData resource name, unique in the permission spaceSample data resource name
resourceCodestringYesData resource Code, unique in the permission spacedataResourceTestCode
typestringYesData resource type, currently supports tree structure (TREE), string (STRING), array (ARRAY)TREE
descriptionstringNoData resource descriptionSample data resource description
structYesData resource structure, supports string (STRING), tree structure (TREE) and array structure (ARRAY).
actionsarrayYesData resource permission operation list. Array length limit: 50.["read","get"]

Agent infrastructure for identity, memory, and web action.