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

Updating an End Device Template

Function

This API is used to update an end device template.

URI

PUT /v2/{project_id}/edgemgr/device-templates/{device_template_id}

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.

device_template_id

Yes

Device template 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

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": {
    "value": "test",
    "optional": true,
    "metadata": {
        "type": "string"
    }
}

tags

No

Table 9 object

Device template tag, in key-value pair format.

access_protocol

No

String

Access protocol. The options are as follows:

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

property_visitors

No

Table 25 object

Twin property configuration, which varies depending on access_protocol.

Table 5 value_in_twin

Parameter

Mandatory

Type

Description

excepted

Yes

Table 6 object

Expected information about dynamic properties.

optional

No

Boolean

Whether the property is optional. The default value is true. The value for properties inherited from a template is false by default.

metadata

No

Table 7 object

Metadata of dynamic properties.

Table 6 excepted

Parameter

Mandatory

Type

Description

value

Yes

String

Initial value of a dynamic property. The value contains a maximum of 512 characters. Only letters, digits, and special characters (_-.,:/@#) are allowed.

metadata

No

Table 8 object

Time when the expected value is set.

Table 7 metadata

Parameter

Mandatory

Type

Description

type

Yes

String

Attribute type ID. Value: string, int, float, or boolean. The type of boolean is true or false. Default value: string.

Table 8 metadata

Parameter

Mandatory

Type

Description

timestamp

No

String

Modification time, which is in Unix timestamp format.

Table 9 ResourceTag

Parameter

Mandatory

Type

Description

key

No

String

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

value

No

String

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

Example request
{    
         "device_template":{
         "description":"This is a camera template",
         "attributes":{
             "cameraURL":{
                 "value":"127.0.0.1",
                 "metadata":{
                     "type":"string"
                 }
             }
         },
         "twin":{
             "runstate":{
                 "expected":{
                     "value":"running"
                 },
                 "metadata":{
                     "type":"string"
                 }
             }
         }
     }
}

Response

Response parameters

Table 10 Parameters in the response body

Parameter

Type

Description

device_template

Table 7 object

Details about the end device template.

Example response

{
     "device_template":{
         "name":"CameraTemplate",
         "description":"This is a camera template",
         "created_at":"2018-07-16T04:01:21.212072",
         "updated_at":"2018-07-18T04:01:21.212017",
         "access_protocol": "userdefine",
         "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.