Updated on 2023-11-23 GMT+08:00

Creating an End Device Template

Function

This API is used to create an end device template.

URI

POST /v2/{project_id}/edgemgr/device-templates

Table 1 Path parameters

Parameter

Mandatory

Description

project_id

Yes

Project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

Request

Request parameters

Table 2 Parameters in the request header

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Message body type (format).

The default value application/json is recommended.

X-Auth-Token

Yes

String

User token. The token can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Table 3 Parameters in the request body

Parameter

Mandatory

Type

Description

device_template

Yes

device_template object

Device template information.

Table 4 device_template

Parameter

Mandatory

Type

Description

name

Yes

String

Device template name. The name contains a maximum of 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

access_protocol

No

String

Access protocol. The options are as follows:

  • userdefine: custom protocol
  • modbus: Modbus protocol
  • opc-ua: OPC UA protocol

The default value is userdefine.

description

No

String

Device template description. The description contains a maximum of 255 characters.

attributes

No

Object

Static properties of an end device. A maximum of 64 key-value pairs are supported.

The key indicates the property name. For details about the format of value, see Table 6. The following is an example:

"attributes": {
            "username": {
                "value": "test",
                "optional": true,
                "metadata": {
                    "type": "string"
                }
            }
        }

twin

No

Object

Dynamic properties of an end device. A maximum of 64 key-value pairs are supported.

The key indicates the property name. For details about the format of value, see Table 7. The following is an example:

"twin": {
            "devicestate": {
                "optional": true,
                "expected": {
                    "value": "running"
                },
                "metadata": {
                    "type": "string"
                }
            }
        }

tags

No

Table 5 object

Device template tag, in key-value pair format.

property_visitors

No

Object

Twin property configuration, which varies depending on access_protocol. The key indicates the property name, which must be the same as the key of twin. For details about the value format, see Table 25.

Table 5 ResourceTag

Parameter

Mandatory

Type

Description

key

Yes

String

Tag key, which can contain a maximum of 36 Unicode characters.

This parameter cannot be left blank and can contain only letters, digits, hyphens (-), and underscores (_).

value

Yes

String

Tag value, which can contain a maximum of 43 Unicode characters. If value is specified, tags are deleted by key and value. If value is not specified, tags are deleted by key.

This parameter cannot be left blank and can contain only letters, digits, hyphens (-), and underscores (_).

Example request

{
    "device_template": {
        "name": "CameraTemplate",
        "access_protocol": "userdefine",
        "description": "This is a camera template",
        "attributes": {
            "cameraURL": {
                "value": "127.0.0.1",
                "optional": true,
                "metadata": {
                    "type": "string"
                }
            }
        },
        "twin": {
            "runstate": {
                "expected": {
                    "value": "running"
                },
                "optional": false,
                "metadata": {
                    "type": "string"
                }
            }
        },
        "tags": {
            "dev": "dev1"
        }
    }
}

Response

Response parameters

Table 6 Parameters in the response body

Parameter

Type

Description

device_template

Table 7 object

End device template information.

Table 7 device_template

Parameter

Type

Description

id

String

End device template ID.

name

String

End device template name.

access_protocol

String

Access protocol.

description

String

End device template description.

attributes

Object

Static properties of an end device. A maximum of 64 key-value pairs are supported.

The key indicates the property name. For details about the format of value, see Table 6. The following is an example:

"attributes": {
            "username": {
                "value": "test",
                "optional": true,
                "metadata": {
                    "type": "string"
                }
            }
        }

twin

Object

Dynamic properties of an end device. A maximum of 64 key-value pairs are supported.

The key indicates the property name. For details about the format of value, see Table 21. The following is an example:

"devicestate":{ 
                      "expected":{ 
                           "value":"running", 
                           "metadata":{ 
                                "timestamp":1536822119463 
                                } 
                           }, 
                     "optional":true, 
                     "metadata":{ "type":"string" } 
                     }

project_id

String

Project ID.

created_at

String

Creation time.

access_config

Table 24 object

Access configuration, which varies depending on access_protocol.

property_visitors

Table 25 object

Twin property configuration, which varies depending on access_protocol.

tags

Table 8 object

Device template tag, in key-value pair format.

Table 8 ResourceTag

Parameter

Type

Description

key

String

Key of a tag. The key must contain 1 to 36 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

value

String

Value of a tag. The value must contain 0 to 43 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

Example response

{
    "device_template": {
        "name": "CameraTemplate",
        "description": "This is a camera template",
        "in_use": null,
        "created_at": "2018-07-16T04:01:21.212072",
        "project_id": "d16e6eb6cc0d49a0941df2f31285757a",
        "id": "82952098-ec24-4643-94e6-9989174fce05",
        "attributes": {
            "cameraURL": {
                "value": "127.0.0.1",
                "metadata": {
                    "type": "string"
                }
            }
            "twin": {
                "runstate": {
                    "expected": {
                        "value": "running"
                    },
                    "metadata": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

Error Codes

For details, see Error Codes.