Updated on 2024-06-27 GMT+08:00

Query Device Properties

Function

A product model defines properties that the platform can deliver to devices. This API is used by an application to query real-time properties of a device. The device returns the query result to the application. This API can only be used for MQTT devices. NB-IoT devices are not supported.

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/{device_id}/properties

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

device_id

Yes

String

Parameter description: ID of the device to which the property is delivered. The ID is unique and is allocated by the platform during device registration. Value: The value can contain a maximum of 128 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

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

service_id

Yes

String

Parameter description: device service ID, which is defined in the product model associated with the device.

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. In the returned response header, X-Subject-Token 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

request_id

String

An ID that uniquely identifies a device property query request. It is unique and is allocated by the platform when delivering a command for device property query.

response

Object

Property execution result reported by the device. The value is in JSON format. The specific format depends on the application and device.

error_code

String

Error code of a property query exception.

error_msg

String

Error message of a property query exception.

Example Requests

Queries all properties of the Temperature service of a specified device.

GET https://{endpoint}/v5/iot/{project_id}/devices/{device_id}/properties?service_id=Temperature

Example Responses

Status code: 200

OK

{
  "request_id" : "b1224afb-e9f0-4916-8220-b6bab568e888",
  "response" : {
    "services" : {
      "serviceId" : "Temperature",
      "properties" : {
        "PhV_phsA" : "1",
        "PhV_phsB" : "2"
      },
      "eventTime" : "20190606T121212Z"
    }
  }
}

Status Codes

Status Code

Description

200

OK

400

Bad Request

401

Unauthorized

403

Forbidden

404

Not Found

500

Internal Server Error

503

Service Unavailable

Error Codes

See Error Codes.