tencent cloud

文档反馈

CreateDevice

最后更新时间:2022-09-28 10:37:23

1. API Description

Domain name for API request: iotcloud.tencentcloudapi.com.

This API is used to create an IoT Hub device.

A maximum of 20 requests can be initiated per second for this API.

We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common Params. The value used for this API: CreateDevice.
Version Yes String Common Params. The value used for this API: 2021-04-08.
Region Yes String Common Params. For more information, please see the list of regions supported by the product.
ProductId Yes String Product ID, globally unique ID assigned by Tencent Cloud during product creation
DeviceName Yes String Device name. It is a string of 1 to 48 characters. Letters, digits, and :_- are allowed.
Attribute No Attribute Device attribute
DefinedPsk No String Whether to use custom PSK, no by default
Isp No Integer ISP, required for a NB-IoT product. 1: China Telecom; 2: China Mobile; 3: China Unicom
Imei No String IMEI, required for a NB-IoT product
LoraDevEui No String DevEUI of a LoRa device, required when you create a LoRa device
LoraMoteType No Integer MoteType of a LoRa device
Skey No String Skey, required when you create a LoRa device
LoraAppKey No String AppKey of a LoRa device
TlsCrt No String Private CA certificate

3. Output Parameters

Parameter Name Type Description
DeviceName String Device name
DevicePsk String Base64-encoded symmetric encryption key, which is returned if symmetric encryption is used
DeviceCert String Device certificate, which authenticates client identity during TLS connection establishment and is returned if asymmetric encryption is used
DevicePrivateKey String Device private key, which authenticates client identity during TLS connection establishment and is returned if asymmetric encryption is used. Tencent Cloud does not store the key. Please store it by yourself properly.
LoraDevEui String DevEUI of a LoRa device, which is returned for a LoRa device
LoraMoteType Integer MoteType of a LoRa device, which is returned for a LoRa device
LoraAppKey String AppKey of a LoRa device, which is returned for a LoRa device
LoraNwkKey String NwkKey of a LoRa device, which is returned for a LoRa device
RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

4. Example

Example1 Creating a device (symmetric encryption)

Input Example

https://iotcloud.tencentcloudapi.com/?Action=CreateDevice
&ProductId=ABCDE12345
&DeviceName=test_device
&Attribute.Tags.0.Tag=note
&Attribute.Tags.0.Type=2
&Attribute.Tags.0.Value=test_note
&<Common request parameters>

Output Example

{
    "Response": {
        "DeviceName": "test_device",
        "DevicePsk": "xxxxxxxxxxxxx",
        "DeviceCert": "",
        "DevicePrivateKey": "",
        "LoraDevEui": "",
        "LoraMoteType": 1,
        "LoraNwkKey": "",
        "LoraAppKey": "xx",
        "RequestId": "54f75f05-a87c-45fc-9520-6b59e251e91c"
    }
}

Example2 Creating a device (asymmetric encryption)

Input Example

https://iotcloud.tencentcloudapi.com/?Action=CreateDevice
&ProductId=ABCDE12345
&DeviceName=test_device
&<Common request parameters>

Output Example

{
    "Response": {
        "DeviceName": "test_device",
        "DevicePsk": "",
        "DeviceCert": "xxxxxxxxxxxxxxxxxxxx",
        "DevicePrivateKey": "xxxxxxxxxxxxxxxxxxxxxxx",
        "LoraDevEui": "",
        "LoraMoteType": 1,
        "LoraNwkKey": "",
        "LoraAppKey": "xx",
        "RequestId": "54f75f05-a87c-45fc-9520-6b59e251e91c"
    }
}

5. Developer Resources

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
FailedOperation.AlreadyDistributionDevice This device has been transferred and cannot be created again.
FailedOperation.TidWhiteListNotOpen You cannot create devices as allowlist authentication is not enabled. IoT Hub will create devices automatically by the names carried during authentication.
InternalError Internal error.
InternalError.DBOperationError An internal database error occurred.
InvalidParameterValue Invalid parameter value.
InvalidParameterValue.DefinedPskNotBase64 Invalid format. DefinedPsk must be a Base64 string.
InvalidParameterValue.DeviceAlreadyExist The device already exists.
InvalidParameterValue.ProductTypeNotSupport Unsupported product type.
LimitExceeded.DeviceExceedLimit Device quantity exceeded the limit.
ResourceNotFound.ProductNotExist The product does not exist.
UnauthorizedOperation.ProductCantHaveLoRaDevice You cannot create a LoRa device under this product type.
UnauthorizedOperation.ProductCantHaveNormalDevice You cannot create a general device under a NB-IoT product.
UnauthorizedOperation.ProductCantHaveNotLoRaDevice You can create only LoRa devices under this product type.
UnauthorizedOperation.ProductIsForbidden This feature has been disabled for the product.
UnauthorizedOperation.ProductNotSupportPSK The product does not support key authentication.
UnsupportedOperation.SuiteTokenNoCreate You cannot create devices under a suite token product.