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.

Note The RAM users of an Alibaba Cloud account share the quota of the Alibaba Cloud account.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

ParameterTypeRequiredExampleDescription
ActionStringYesImportDevice

The operation that you want to perform. Set the value to ImportDevice.

ProductKeyStringYesa1BwAGV****

The ProductKey of the product to which the device belongs.

DeviceNameStringYeslight

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.

DeviceSecretStringYesb4d43f7******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 (:).

NicknameStringNoCampus 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.
SnStringNoQC4******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.
IotInstanceIdStringNoiot-1n8t****

The ID of the instance. You can obtain the ID of the instance on the Overview page in the IoT Platform console.

Important
  • If your instance has an ID, you must specify the ID for this parameter. Otherwise, the call fails.
  • If no Overview page or ID is generated for your instance, you do not need to configure this parameter.

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

ParameterTypeExampleDescription
CodeStringiot.system.SystemException

The error code returned if the call fails. For more information, see Error codes.

DataStruct

The device information returned if the call is successful.

DeviceNameStringlight

The DeviceName of the device.

Important

Keep the information confidential.

DeviceSecretStringb4d43f7******10ba5e5

The DeviceSecret of the device.

Important

Keep the information confidential.

IotIdString1O4YPNtRqB2anumz2Canp4GB7*****

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.

NicknameStringCampus light

The alias of the device.

Note If you do not specify an alias for the device, this parameter is empty.
ProductKeyStringa1BwAGV****

The ProductKey of the product to which the device belongs.

SnStringQC4******001

The SN of the device.

Note If you do not specify an SN for the device, this parameter is empty.
ErrorMessageStringA system exception occurred.

The error message returned if the call fails.

RequestIdStringE4C0FF92-2A86-41DB-92D3-73B60310D25E

The ID of the request.

SuccessBooleantrue

Indicates whether the call was successful.

  • true: The call was successful.
  • false: The call failed.

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

HttpCodeError codeError messageDescription
200iot.device.CreateDeviceFailedAn error occurred while creating the device.The error message returned because the system failed to create the device.
200iot.device.AlreadyExistedDeviceNameThe DeviceName already exists.The error message returned because the DeviceName already exists.

For a list of error codes, see Service error codes.