Updated on 2024-12-02 GMT+08:00

Query the Device List

Function

This API is used by an application to query the device list on the IoT platform.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

URI

GET /v5/iot/{project_id}/devices

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Parameter description: project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

product_id

No

String

Parameter description: unique ID of the product associated with the device. The value is allocated by the platform after the product is created. For details, see Creating a Product.

Value: The value can contain a maximum of 36 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

gateway_id

No

String

Parameter description: gateway ID, which is the device ID of the parent device. If this parameter is carried, child devices under the parent device are queried. By default, the child devices at the nearest lower level are queried. To query all levels of child devices, set is_cascade_query to true. If this parameter is not carried, all your devices are queried.

Value: The value can contain a maximum of 128 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

is_cascade_query

No

Boolean

Parameter description: whether cascading query is performed. This parameter is valid only when gateway_id is carried. The default value is false.

Options:

  • true: All child devices under the device whose ID is the value of gateway_id are queried.

  • false: The child devices at the nearest lower level under the device whose ID is the value of gateway_id are queried.

node_id

No

String

Parameter description: device identifier. This parameter is set to the IMEI, MAC address, or serial number.

Value: The value can contain a maximum of 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

device_name

No

String

** Parameter description**: device name, which uniquely identifies a device in a resource space.

Value: The value can contain a maximum of 256 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

limit

No

Integer

Parameter description: number of records to display on each page.

Value: The value is an integer ranging from 1 to 50. The default value is 10.

marker

No

String

Parameter description: ID of the last record in the previous query. The value is returned by the platform during the previous query. Records are queried in descending order of record IDs (the marker value). A newer record will have a larger ID. If marker is specified, only the records whose IDs are smaller than marker are queried. If marker is not specified, the query starts from the record with the largest ID, that is, the latest record. If all data needs to be queried in sequence, this parameter must be filled with the value of marker returned in the last query response each time.

Value: The value is a string of 24 hexadecimal characters. The default value is ffffffffffffffffffffffff.

offset

No

Integer

Parameter description: If offset is set to N, the query starts from the N+1 record after the last record in the previous query. The value is an integer ranging from 0 to 500. The default value is 0. If offset is set to 0, the output starts from the first record after the last record in the previous query. To ensure API performance, you can use this parameter together with marker to turn pages. For example, if there are 50 records on each page, you can directly specify offset to jump to the specified page within page 1 and 11. If you want to view records displayed on pages 12 to 22, you need to use the marker value returned on page 11 as the marker value for the next query.

Value: The value is an integer ranging from 0 to 500. The default value is 0.

start_time

No

String

Parameter description: Records of devices registered after the value of this parameter are queried. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

end_time

No

String

Parameter description: Records of devices registered before the value of this parameter are queried. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

app_id

No

String

Parameter description: resource space ID. This parameter is optional. If you have multiple resource spaces, you can specify this parameter to query devices in the specified resource space. If this parameter is not carried, devices in all resource spaces are queried.

Value: The value can contain a maximum of 36 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

Request Parameters

Table 3 Request header 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. X-Subject-Token in the response header returned by the API 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.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

devices

Array of QueryDeviceSimplify objects

Device information list.

page

Page object

Pagination information of the query results.

Table 5 QueryDeviceSimplify

Parameter

Type

Description

app_id

String

Resource space ID.

app_name

String

Resource space name.

device_id

String

Device ID, used to uniquely identify a device. The value of this parameter is specified during device registration or allocated by the platform. If the value is allocated by the platform, the value is in the format of [product_id]_[node_id].

node_id

String

Device identifier. This parameter is set to the IMEI, MAC address, or serial number.

gateway_id

String

Gateway ID, which is the device ID of the parent device. The gateway ID is the same as the device ID if the device is a directly connected device. If the device is an indirectly connected device, the gateway ID is the device ID of the directly connected device with which it associates.

device_name

String

Device name.

node_type

String

Device node type.

  • ENDPOINT: an indirectly connected device.

  • GATEWAY: a directly connected device or gateway.

  • UNKNOWN: The device node type is unknown.

description

String

Device description.

fw_version

String

Firmware version of the device.

sw_version

String

Software version of the device.

device_sdk_version

String

Device SDK information.

product_id

String

Unique ID of the product associated with the device.

product_name

String

Name of the product associated with the device.

status

String

Device status.

  • ONLINE: The device is online.

  • OFFLINE: The device is offline.

  • ABNORMAL: The device is abnormal.

  • INACTIVE: The device is not activated.

  • FROZEN: The device is frozen.

tags

Array of TagV5DTO objects

List of device tags.

Table 6 TagV5DTO

Parameter

Type

Description

tag_key

String

Parameter description: tag key, which is unique for a resource. If the specified key already exists, the value of the existing tag is overwritten. If the specified key does not exist, a new tag is added.

Value: The value can contain a maximum of 64 characters. Only letters, digits, underscores (_), periods (.), and hyphens (-) are allowed.

tag_value

String

Parameter description: tag value.

Value: The value can contain a maximum of 128 characters. Only letters, digits, underscores (_), periods (.), and hyphens (-) are allowed.

Table 7 Page

Parameter

Type

Description

count

Long

Total number of records that meet the query conditions.

marker

String

ID of the last record in this query, which can be used in the next query.

Example Requests

Queries all devices in a list.

GET https://{endpoint}/v5/iot/{project_id}/devices

Example Responses

Status code: 200

OK

{
  "devices" : [ {
    "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka",
    "app_name" : "testAPP01",
    "device_id" : "d4922d8a-6c8e-4396-852c-164aefa6638f",
    "node_id" : "ABC123456789",
    "gateway_id" : "d4922d8a-6c8e-4396-852c-164aefa6638f",
    "device_name" : "dianadevice",
    "node_type" : "ENDPOINT",
    "description" : "watermeter device",
    "fw_version" : "1.1.0",
    "sw_version" : "1.1.0",
    "product_id" : "b640f4c203b7910fc3cbd446ed437cbd",
    "product_name" : "Thermometer",
    "status" : "INACTIVE",
    "tags" : [ {
      "tag_key" : "testTagName",
      "tag_value" : "testTagValue"
    } ]
  } ],
  "page" : {
    "count" : 100,
    "marker" : "5c8f3d2d3df1f10d803adbda"
  }
}

Status Codes

Status Code

Description

200

OK

400

Bad Request

401

Unauthorized

403

Forbidden

500

Internal Server Error

Error Codes

See Error Codes.