Create a Pre-provisioning Template
Function
This API is used by an application to create a pre-provisioning template on the IoT platform. For a device not registered, you can use a pre-provisioning template to automatically register the device information on the IoT platform when the device connects to the platform for the first time.
-
A pre-provisioning template takes effect only after it is bound to at least one device CA certificate.
-
An instance can have a maximum of 10 pre-provisioning templates.
-
This API is supported only by standard and enterprise editions.
Debugging
You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.
URI
POST /v5/iot/{project_id}/provisioning-templates
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Parameter description: project ID. For details, see Obtaining a Project ID. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
No |
String |
Parameter description: user token. You can obtain the token by calling the IAM API Obtaining a User Token Through Password Authentication. In the returned response header, X-Subject-Token is the desired user token. For details about how to obtain the token, see Token Authentication. |
Instance-Id |
No |
String |
Parameter description: instance ID. Unique identifier of each instance in the physical multi-tenant scenario. Mandatory for professional editions and recommended in other cases. Log in to the IoTDA console and choose Overview in the navigation pane to view the instance ID. For details, see Viewing Instance Details. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
template_name |
Yes |
String |
Parameter description: name of the pre-provisioning template. Value: The value can contain a maximum of 128 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. |
description |
No |
String |
Parameter description: description of the pre-provisioning template. Value: The value can contain a maximum of 2,048 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed. |
template_body |
Yes |
ProvisioningTemplateBody object |
Parameter description: detailed content of the pre-provisioning template in JSON format. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
parameters |
Yes |
Object |
Parameter description: pre-provisioning template parameters, which can be extracted from the user fields of pre-provisioning device certificates. The configuration format is {"parameter":{"type":"String"}}. Huawei Cloud IoT platform defines the parameters that can be declared and referenced in pre-provisioning templates. A device certificate must contain the parameters referenced in the template.
type indicates the parameter type. Currently, only String is supported. Configuration example: '{"iotda::certificate::country":{"type":"String"}, "iotda::certificate::organization":{"type":"String"}, "iotda::certificate::organizational_unit":{"type":"String"}, "iotda::certificate::distinguished_name_qualifier":{"type":"String"}, "iotda::certificate::state_name":{"type":"String"}, "iotda::certificate::common_name":{"type":"String"}, "iotda::certificate::serial_number":{"type":"String"}}' |
resources |
Yes |
TemplateResource object |
Structure of device resources of a pre-provisioning template. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
device |
Yes |
DeviceResource object |
Structure of device resource details of a pre-provisioning template. |
policy |
No |
PolicyResource object |
Structure of device policy resource details of a pre-provisioning template. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
device_name |
No |
ParameterRef object |
Device name. |
node_id |
Yes |
ParameterRef object |
Node ID. |
product_id |
Yes |
Object |
Parameter description: ID of the product to which the device belongs. The value can be a static string ID or dynamic parameters referenced from the template.
|
tags |
No |
Array of TagRef objects |
Parameter description: list of tags bound to a device. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
tag_key |
No |
Object |
Parameter description: tag key name. The value can be a static string or dynamic parameters referenced from the template.
|
tag_value |
No |
Object |
Parameter description: tag value. The value can be a static string or dynamic parameters referenced from the template.
|
Response Parameters
Status code: 201
Parameter |
Type |
Description |
---|---|---|
template_id |
String |
Parameter description: ID of the pre-provisioning template. |
template_name |
String |
Parameter description: name of the pre-provisioning template. Value: The value can contain a maximum of 128 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. |
description |
String |
Parameter description: description of the pre-provisioning template. Value: The value can contain a maximum of 2,048 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed. |
template_body |
ProvisioningTemplateBody object |
Parameter description: detailed content of the pre-provisioning template in JSON format. |
create_time |
String |
Time when a pre-provisioning template is created on the IoT platform. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z. |
update_time |
String |
Time when the pre-provisioning template is updated in the IoT platform. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z. |
Parameter |
Type |
Description |
---|---|---|
parameters |
Object |
Parameter description: pre-provisioning template parameters, which can be extracted from the user fields of pre-provisioning device certificates. The configuration format is {"parameter":{"type":"String"}}. Huawei Cloud IoT platform defines the parameters that can be declared and referenced in pre-provisioning templates. A device certificate must contain the parameters referenced in the template.
type indicates the parameter type. Currently, only String is supported. Configuration example: '{"iotda::certificate::country":{"type":"String"}, "iotda::certificate::organization":{"type":"String"}, "iotda::certificate::organizational_unit":{"type":"String"}, "iotda::certificate::distinguished_name_qualifier":{"type":"String"}, "iotda::certificate::state_name":{"type":"String"}, "iotda::certificate::common_name":{"type":"String"}, "iotda::certificate::serial_number":{"type":"String"}}' |
resources |
TemplateResource object |
Structure of device resources of a pre-provisioning template. |
Parameter |
Type |
Description |
---|---|---|
device |
DeviceResource object |
Structure of device resource details of a pre-provisioning template. |
policy |
PolicyResource object |
Structure of device policy resource details of a pre-provisioning template. |
Parameter |
Type |
Description |
---|---|---|
device_name |
ParameterRef object |
Device name. |
node_id |
ParameterRef object |
Node ID. |
product_id |
Object |
Parameter description: ID of the product to which the device belongs. The value can be a static string ID or dynamic parameters referenced from the template.
|
tags |
Array of TagRef objects |
Parameter description: list of tags bound to a device. |
Parameter |
Type |
Description |
---|---|---|
tag_key |
Object |
Parameter description: tag key name. The value can be a static string or dynamic parameters referenced from the template.
|
tag_value |
Object |
Parameter description: tag value. The value can be a static string or dynamic parameters referenced from the template.
|
Example Requests
-
Creates a pre-provisioning template with parameter reference.
POST https://{endpoint}/v5/iot/{project_id}/provisioning-templates { "template_name" : "myTemplate", "description" : "myTemplate", "template_body" : { "parameters" : { "iotda::certificate::country" : { "type" : "String" }, "iotda::certificate::organization" : { "type" : "String" }, "iotda::certificate::organizational_unit" : { "type" : "String" }, "iotda::certificate::distinguished_name_qualifier" : { "type" : "String" }, "iotda::certificate::state_name" : { "type" : "String" }, "iotda::certificate::common_name" : { "type" : "String" }, "iotda::certificate::serial_number" : { "type" : "String" } }, "resources" : { "device" : { "device_name" : { "ref" : "iotda::certificate::organization" }, "node_id" : { "ref" : "iotda::certificate::common_name" }, "product_id" : { "ref" : "iotda::certificate::organization" }, "tags" : [ { "tag_key" : { "ref" : "iotda::certificate::organization" }, "tag_value" : { "ref" : "iotda::certificate::organizational_unit" } } ] }, "policy" : { "policy_ids" : [ "5c90fa7d3c4e4405e8525079" ] } } } }
-
Creates a pre-provisioning template some custom parameters.
POST https://{endpoint}/v5/iot/{project_id}/provisioning-templates { "template_name" : "myTemplate2", "description" : "myTemplate2", "template_body" : { "parameters" : { "iotda::certificate::country" : { "type" : "String" }, "iotda::certificate::organization" : { "type" : "String" }, "iotda::certificate::organizational_unit" : { "type" : "String" }, "iotda::certificate::distinguished_name_qualifier" : { "type" : "String" }, "iotda::certificate::state_name" : { "type" : "String" }, "iotda::certificate::common_name" : { "type" : "String" }, "iotda::certificate::serial_number" : { "type" : "String" } }, "resources" : { "device" : { "device_name" : { "ref" : "iotda::certificate::organization" }, "node_id" : { "ref" : "iotda::certificate::common_name" }, "product_id" : "642bf260f2f9030e44210d8d", "tags" : [ { "tag_key" : "myTagKey", "tag_value" : "myTagValue" } ] }, "policy" : { "policy_ids" : [ "5c90fa7d3c4e4405e8525079" ] } } } }
Example Responses
Status code: 201
Created
{ "template_id" : "5c90fa7d3c4e4405e8525079", "template_name" : "myTemplate", "description" : "myTemplate", "template_body" : { "parameters" : { "iotda::certificate::country" : { "type" : "String" }, "iotda::certificate::organization" : { "type" : "String" }, "iotda::certificate::organizational_unit" : { "type" : "String" }, "iotda::certificate::distinguished_name_qualifier" : { "type" : "String" }, "iotda::certificate::state_name" : { "type" : "String" }, "iotda::certificate::common_name" : { "type" : "String" }, "iotda::certificate::serial_number" : { "type" : "String" } }, "resources" : { "device" : { "device_name" : { "ref" : "iotda::certificate::organization" }, "node_id" : { "ref" : "iotda::certificate::common_name" }, "product_id" : { "ref" : "iotda::certificate::organization" } }, "policy" : { "policy_ids" : [ "5c90fa7d3c4e4405e8525079" ] } } }, "create_time" : "20230810T070547Z", "update_time" : "20230810T070547Z" }
Status Codes
Status Code |
Description |
---|---|
201 |
Created |
400 |
Bad Request |
401 |
Unauthorized |
403 |
Forbidden |
500 |
Internal Server Error |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot