Queries the devices of a product.

Description

The QueryDevice operation can return up to one million devices each time you call the operation.

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.
  • If the product of the value of the CurrentPage parameter and the value of the PageSize parameter is greater than or equal to 100,000, the queries per second (QPS) of this operation decreases.

    In this case, you can call this API operation up to two times per second per 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
ActionStringYesQueryDevice

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

ProductKeyStringYesa1BwAGV****

The ProductKey of the product to which the device belongs.

IotInstanceIdStringNoiot_instc_pu****_c*-v64********

The ID of the instance. You can view 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.

PageSizeIntegerNo10

The number of entries to return on each page. Valid values: 1 to 50. Default value: 10.

CurrentPageIntegerNo1

The number of the page to return. Default value: 1.

NextTokenStringNoTGlzdFJlc291cm***

The token that is used to retrieve the next page of the query results. The first time you perform a query operation, you do not need to configure this parameter. You must specify the token that is obtained from the previous query for the NextToken parameter.

If the product of the value of the PageSize parameter and the value of the CurrentPage parameter is greater than 10,000, you must configure the NextToken parameter. Otherwise, data cannot be returned.

Important

If you configure the NextToken parameter, the product of the value of the PageSize parameter and the value of the CurrentPage parameter must be less than 1,000,000. Otherwise, data cannot be returned.

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.

DataArray of DeviceInfo

The device information returned if the call is successful. The details of the devices are included in the DeviceInfo parameter.

Note The returned device information is sorted in reverse chronological order based on the time when the devices were created.
DeviceInfo
DeviceIdStringdwnS41bhNxjslDAI****

The ID of the device.

Note This parameter is deprecated. Do not use this parameter to identify a device. You can use the IotId parameter or a combination of the ProductKey and DeviceName parameters to identify a device.
DeviceNameStringlight

The name of the device.

DeviceSecretStringsLefbFmN9SYfnWLJTePG893XNuRV****

The DeviceSecret of the device.

DeviceStatusStringONLINE

The status of the device. Valid values:

  • ONLINE: The device is online.
  • OFFLINE: The device is offline.
  • UNACTIVE: The device is not activated.
  • DISABLE: The device is deactivated.
DeviceTypeStringLighting

The category of the product to which the device belongs.

Note This parameter is not returned.
GmtCreateStringWed, 20-Feb-2019 02:16:09 GMT

The time when the device was created. The time is in the GMT format.

GmtModifiedStringWed, 20-Feb-2019 02:16:09 GMT

The time when the device information was last updated. The time is in the GMT format.

IotIdStringQ7uOhVRdZRRlDnTLv****00100

The ID of the device. The ID is a unique identifier that is issued by IoT Platform to the device.

NicknameStringSmart light

The alias of the device.

ProductKeyStringa1BwAGV****

The ProductKey of the product to which the device belongs.

UtcCreateString2019-02-20T02:16:09.000Z

The time when the device was created. The time is displayed in UTC.

UtcModifiedString2019-02-20T02:16:09.000Z

The time when the device information was last updated. The time is displayed in UTC.

ErrorMessageStringA system exception occurred.

The error message returned if the call fails.

NextTokenStringTGlzdFJlc291cm***

The token that is used to retrieve the subsequent page of the query results. You can specify this parameter in the subsequent query to obtain the next page of results.

If the NextToken parameter is empty, no subsequent page exists.

PageInteger1

The page number of the returned page.

PageCountInteger1

The total number of pages returned.

PageSizeInteger10

The number of entries returned per page.

RequestIdStringE55E50B7-40EE-4B6B-8BBE-D3ED55CCF565

The ID of the request.

SuccessBooleantrue

Indicates whether the call was successful. Valid values:

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

The total number of devices.

Examples

Sample requests

https://iot.cn-shanghai.aliyuncs.com/?Action=QueryDevice
&ProductKey=aldafD****
&PageSize=10
&CurrentPage=1
&<Common request parameters>

Sample success responses

XML format

<QueryDeviceResponse>
  <PageCount>1</PageCount>
  <NextToken>TGlzdFJlc291cm***</NextToken>
  <Data>
        <DeviceInfo>
              <DeviceId>Av8NGHGtwPrH9BYG****</DeviceId>
              <DeviceName>Av8NGHGtwPrH9BYGLMBi</DeviceName>
              <ProductKey>a1dafDE****</ProductKey>
              <DeviceSecret>d7GYhf5hfcPHDe1bXSd3n9MjO1G3****</DeviceSecret>
              <UtcModified>2019-02-20T02:16:09.000Z</UtcModified>
              <GmtCreate>Wed, 20-Feb-2019 02:16:09 GMT</GmtCreate>
              <UtcCreate>2019-02-20T02:16:09.000Z</UtcCreate>
              <GmtModified>Wed, 20-Feb-2019 02:16:09 GMT</GmtModified>
              <IotId>Av8NGHGtwPrH9BYGLMBi00****</IotId>
              <DeviceStatus>UNACTIVE</DeviceStatus>
              <Nickname>SensorInShanghai</Nickname>
        </DeviceInfo>
        <DeviceInfo>
              <DeviceId>zNIcSmWQ9BPJlmkj****</DeviceId>
              <DeviceName>zNIcSmWQ9BPJlmkjn3H1</DeviceName>
              <ProductKey>a1dafDE****</ProductKey>
              <DeviceSecret>C27XXmC18yLIEDXvUj6FSlvgO7ag****</DeviceSecret>
              <UtcModified>2019-02-20T02:16:09.000Z</UtcModified>
              <GmtCreate>Wed, 20-Feb-2019 02:16:09 GMT</GmtCreate>
              <UtcCreate>2019-02-20T02:16:09.000Z</UtcCreate>
              <GmtModified>Wed, 20-Feb-2019 02:16:09 GMT</GmtModified>
              <IotId>zNIcSmWQ9BPJlmkjn3H100****</IotId>
              <DeviceStatus>UNACTIVE</DeviceStatus>
              <Nickname>DriverInShanghai</Nickname>
        </DeviceInfo>
  </Data>
  <Page>1</Page>
  <PageSize>10</PageSize>
  <RequestId>CD9E5F99-A095-4A05-9256-D924EA3075E8</RequestId>
  <Success>true</Success>
  <Total>2</Total>
</QueryDeviceResponse>

JSON format

{
  "PageCount": 1,
  "NextToken":"TGlzdFJlc291cm***", 
  "Data": {
    "DeviceInfo": [
      {
        "DeviceId": "Av8NGHGtwPrH9BYG****", 
        "DeviceName": "Av8NGHGtwPrH9BYGLMBi", 
        "ProductKey": "a1dafDE****", 
        "DeviceSecret": "d7GYhf5hfcPHDe1bXSd3n9MjO1G3****", 
        "UtcModified": "2019-02-20T02:16:09.000Z", 
        "GmtCreate": "Wed, 20-Feb-2019 02:16:09 GMT", 
        "UtcCreate": "2019-02-20T02:16:09.000Z", 
        "GmtModified": "Wed, 20-Feb-2019 02:16:09 GMT", 
        "IotId": "Av8NGHGtwPrH9BYGLMBi00****", 
        "DeviceStatus": "UNACTIVE", 
        "Nickname": "SensorInShanghai"
      }, 
      {
        "DeviceId": "zNIcSmWQ9BPJlmkj****", 
        "DeviceName": "zNIcSmWQ9BPJlmkjn3H1", 
        "ProductKey": "a1dafDE****", 
        "DeviceSecret": "C27XXmC18yLIEDXvUj6FSlvgO7ag****", 
        "UtcModified": "2019-02-20T02:16:09.000Z", 
        "GmtCreate": "Wed, 20-Feb-2019 02:16:09 GMT", 
        "UtcCreate": "2019-02-20T02:16:09.000Z", 
        "GmtModified": "Wed, 20-Feb-2019 02:16:09 GMT", 
        "IotId": "zNIcSmWQ9BPJlmkjn3H100****", 
        "DeviceStatus": "UNACTIVE", 
        "Nickname": "DriverInShanghai"
      }
    ]
  }, 
  "Page": 1, 
  "PageSize": 10, 
  "RequestId": "CD9E5F99-A095-4A05-9256-D924EA3075E8", 
  "Success": true, 
  "Total": 2
}

Error codes

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