Adds a device to an MQTT gateway product.
Usage notes
Before you call this operation, make sure that an MQTT gateway and the related product are created and the ProductKey of the product is obtained.
QPS limits
You can call this API operation up to 50 times per second per account.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | ImportDevice | The operation that you want to perform. Set the value to ImportDevice. |
ProductKey | String | Yes | a1BwAGV**** | The ProductKey of the product to which the device belongs. |
DeviceName | String | Yes | light | The DeviceName of the device. The DeviceName must be 4 to 32 characters in length, and can contain letters, digits, hyphens (-), underscores (_), at signs (@), periods (.), and colons (:). The DeviceName must be unique in the product. |
DeviceSecret | String | Yes | b4d43f7******10ba5e5 | The DeviceSecret of the device. The DeviceSecret must be 1 to 32 characters in length, and can contain letters, digits, hyphens (-), underscores (_), at signs (@), periods (.), and colons (:). |
Nickname | String | No | Campus light | The alias of the device. The alias must be 1 to 64 characters in length, and can contain letters, digits, and underscores (_). Note If you do not configure this parameter, IoT Platform does not generate an alias for the device. |
Sn | String | No | QC4******001 | The serial number (SN) of the device. The SN must be 1 to 64 characters in length, and can contain letters, digits, and underscores (_). Note If you do not configure this parameter, IoT Platform does not generate an SN for the device. |
IotInstanceId | String | No | iot-1n8t**** | The ID of the instance. You can obtain the ID of the instance on the Overview page in the IoT Platform console. Important
For more information, see Overview. |
In addition to the preceding operation-specific request parameters, you must configure common request parameters when you call this operation. For more information about common request parameters, see Common parameters.
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
Code | String | iot.system.SystemException | The error code returned if the call fails. For more information, see Error codes. |
Data | Struct | The device information returned if the call is successful. | |
DeviceName | String | light | The DeviceName of the device. Important Keep the information confidential. |
DeviceSecret | String | b4d43f7******10ba5e5 | The DeviceSecret of the device. Important Keep the information confidential. |
IotId | String | 1O4YPNtRqB2anumz2Canp4GB7***** | The ID of the device. The ID is a unique identifier that is issued by IoT Platform to the device. Important Keep the information confidential. |
Nickname | String | Campus light | The alias of the device. Note If you do not specify an alias for the device, this parameter is empty. |
ProductKey | String | a1BwAGV**** | The ProductKey of the product to which the device belongs. |
Sn | String | QC4******001 | The SN of the device. Note If you do not specify an SN for the device, this parameter is empty. |
ErrorMessage | String | A system exception occurred. | The error message returned if the call fails. |
RequestId | String | E4C0FF92-2A86-41DB-92D3-73B60310D25E | The ID of the request. |
Success | Boolean | true | Indicates whether the call was successful.
|
Examples
Sample requests
http(s)://iot.cn-shanghai.aliyuncs.com/?Action=ImportDevice
&DeviceName=device1
&DeviceSecret=b4d43f7******10ba5e5
&ProductKey=a1BwAGV****
&IotInstanceId=iot-1n8t****
&<Common request parameters>
Sample success responses
XML
format
<ImportDeviceResponse>
<RequestId>E4C0FF92-2A86-41DB-92D3-73B60310D25E</RequestId>
<Data>
<IotId>1O4YPNtRqB2anumz2Canp4GB7*****</IotId>
<DeviceSecret>b4d43f7******10ba5e5</DeviceSecret>
<Sn>QC4******001</Sn>
<ProductKey>a1BwAGV****</ProductKey>
<Nickname>Campus light</Nickname>
<DeviceName>light</DeviceName>
</Data>
<Success>true</Success>
</ImportDeviceResponse>
JSON
format
{
"RequestId": "E4C0FF92-2A86-41DB-92D3-73B60310D25E",
"Data": {
"IotId": "1O4YPNtRqB2anumz2Canp4GB7*****",
"DeviceSecret": "b4d43f7******10ba5e5",
"Sn": "QC4******001",
"ProductKey": "a1BwAGV****",
"Nickname": "Campus light",
"DeviceName": "light"
},
"Success": true
}
Error codes
HttpCode | Error code | Error message | Description |
---|---|---|---|
200 | iot.device.CreateDeviceFailed | An error occurred while creating the device. | The error message returned because the system failed to create the device. |
200 | iot.device.AlreadyExistedDeviceName | The DeviceName already exists. | The error message returned because the DeviceName already exists. |
For a list of error codes, see Service error codes.