Thing model services

Updated at:

This topic describes a set of service APIs for things, which are devices in the Internet of Things (IoT). Cloud applications can use these APIs to query and control thing information, such as their basic information and property templates.

Get thing properties

Definition

PathVersionDescriptioncloudToken required
/cloud/thing/properties/get1.0.2Gets the snapshot data of all properties of a thing.Yes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNo (required under specific conditions)The unique identifier of the thing. This parameter is required if productKey and deviceName are empty.
productKeyStringNo (required under specific conditions)The unique identifier of the product. This parameter is required if iotId is empty.
deviceNameStringNo (required under specific conditions)The device name. This parameter is required if iotId is empty.

Response parameters

ParameterSub-parameterTypeDescription
dataArrayThe list of data.
attributeStringThe property name.
batchIdStringThe batch ID for the batch property report from the device.
gmtModifiedDateThe time when the device property was collected.
iotIdStringThe unique value of the device.
valueObjectThe property value.

Examples

  • Request example
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.2",
            "cloudToken": "token"
        },
        "params": {
            "iotId": "D95D242xxxx4F31A2697"
        }
    }
                        
  • Successful response
    {
        "code":200,
        "data":[
            {
                "attribute":"AppointmentTime",
                "batchId":"992751fxxxx5b00dac8f4f",
                "gmtModified":1566026333540,
                "iotId":"D95D2xxxxE4F31A2697",
                "value":0
            },
            {
                "attribute":"CO2",
                "batchId":"5729c1c31c6xxxx25fa3b8e",
                "gmtModified":156xxxx430,
                "iotId":"D95D24xxxxF31A2697",
                "value":825
            }
        ],
        "message":"success"
    }

Get a thing template

Definition

PathVersionDescriptioncloudToken required
/cloud/thing/tsl/get1.0.2Gets the Thing Specification Language (TSL) template of a thing. The template includes definitions for properties, events, and services.Yes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNo (required under specific conditions)The unique identifier of the thing. This parameter is required if productKey and deviceName are empty.
productKeyStringNo (required under specific conditions)The unique identifier of the product. This parameter is required if iotId is empty.
deviceNameStringNo (required under specific conditions)The device name. This parameter is required if iotId is empty.

Response parameters

None

Examples

  • Request example
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.2",
            "cloudToken": "token"
        },
        "params": {
            "iotId": "D95D2xxxx4F31A2697"
        }
    }
                        
  • Successful response
    {
        "code": 200,
        "data": {
            "schema": "http://aliyun/iot/thing/desc/schema",
            "profile": {
                "productKey": "xxxxxxx",
                "deviceName": "xxxxxxxxxxxxxxxx"
            },
            "link": "/sys/a1xxxxpck/YzqExxxxjjo/thing/",
            "services": [
                {
                    "outputData": [
    
                    ],
                    "identifier": "ToggleLightSwitch",
                    "inputData": [
    
                    ],
                    "method": "thing.service.ToggleLightSwitch",
                    "name": "Flip main light switch",
                    "required": false,
                    "callType": "async"
                }
            ],
            "properties": [
                {
                    "identifier": "LightSwitch",
                    "dataType": {
                        "specs": {
                            "0": "Off",
                            "1": "On"
                        },
                        "type": "bool"
                    },
                    "name": "Main light switch",
                    "accessMode": "rw",
                    "required": true
                }
            ],
            "events": [
                {
                    "outputData": [
                        {
                            "identifier": "ErrorCode",
                            "dataType": {
                                "specs": {
                                    "0": "Normal"
                                },
                                "type": "enum"
                            },
                            "name": "Error code"
                        }
                    ],
                    "identifier": "Error",
                    "method": "thing.event.Error.post",
                    "name": "Report error",
                    "type": "info",
                    "required": true
                }
            ]
        },
        "message": "success",
    }

Trigger service

Description

PathVersionDescriptioncloudToken required
/cloud/thing/service/invoke1.0.2Trigger ServiceYes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNoThe unique identifier of the thing. If this parameter is not empty, it is used with priority.
productKeyStringYesThe unique identifier of the product. This parameter is required.
deviceNameStringYesThe device name. This parameter is required.
identifierStringYesThe service identifier.
argsJSONYesThe input parameters for the service.

Response parameters

ParameterTypeDescription
dataObjectThe type and value of this response parameter depend on the implementation logic on the device.

Examples

  • Example request
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.1",
            "cloudToken": "token"
        },
        "params": {
            "iotId": "D95D2429xxxx4F31A2697",
            "identifier": "xxxx",
            "args": {}
        }
    }
                        
  • Example of a successful response
    {
      "code": 200,
      "data": null,
      "message": "success",
      "localizedMsg": ""
    }
                        

Set thing properties

Definition

PathVersionDescriptioncloudToken required
/cloud/thing/properties/set1.0.2Sets the properties of a thing.Yes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNo (required under specific conditions)The unique identifier of the thing. This parameter is required if productKey and deviceName are empty.
productKeyStringNo (required under specific conditions)The unique identifier of the product. This parameter is required if iotId is empty.
deviceNameStringNo (required under specific conditions)The device name. This parameter is required if iotId is empty.
itemsJSONYesThe parameters to set.

Response parameters

None

Examples

  • Request example
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.2",
            "cloudToken": "token"
        },
        "params": {
            "iotId": "D95D24xxxxE4F31A2697",
            "items": {
                "LightSwitch1": 0,
                "LightSwitch2": 0
            }
        }
    }
                        
  • Successful response
    {
      "code": 200,
      "data": null,
      "message": "success",
      "localizedMsg": ""
    }
                        

Get the connection status of a thing

Description

PathVersionDescriptioncloudToken required
/cloud/thing/status/get1.0.2Gets the connection status of a thing.Yes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNo (required under specific conditions)The unique identifier of the thing. This parameter is required if productKey and deviceName are empty.
productKeyStringNo (required under specific conditions)The unique identifier of the product. This parameter is required if iotId is empty.
deviceNameStringNo (required under specific conditions)The device name. This parameter is required if iotId is empty.

Response parameters

ParameterTypeDescription
statusIntegerThe device status.
  • 0: Inactive
  • 1: Online
  • 3: Offline
  • 8: Disabled
timeLongThe time when the status changed.

Examples

  • Request example
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.2",
            "cloudToken": "token"
        },
        "params": {
            "iotId": "D95D24xxxxCCE4F31A2697"
        }
    }
                        
  • Successful response
    {
      "code": 200,
      "data": {
        "time": 1517923297000,
        "status": 3
      },
      "message": "success",
      "localizedMsg": null,
    }
                        

Get the basic information of a thing

Description

PathVersionDescriptioncloudToken required
/cloud/thing/info/get1.0.2Gets the basic information of a thing.Yes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNo (required under specific conditions)The unique identifier of the thing. This parameter is required if productKey and deviceName are empty.
productKeyStringNo (required under specific conditions)The unique identifier of the product. This parameter is required if iotId is empty.
deviceNameStringNo (required under specific conditions)The device name. This parameter is required if iotId is empty.

Response parameters

ParameterTypeDescription
gmtModifiedLongThe time when the data was modified.
activeTimeLongThe time when the device was activated.
gmtCreateLongThe time when the device was created.
productKeyStringThe unique identifier of the product.
statusLastIntegerThe previous status of the device.
macStringThe MAC address.
deviceSecretStringThe DeviceSecret of the device.
iotIdStringThe unique identifier of the device.
nameStringThe device name.
nicknameStringThe device nickname.
sdkVersionStringThe SDK version.
snStringThe device SN.
thingTypeStringThe device type.
regionStringThe region.
firmwareVersionStringThe firmware version number.
rbacTenantIdStringThe tenant ID.
statusIntegerDevice Status

Examples

  • Request example
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.2",
            "cloudToken": "token"
        },
        "params": {
            "iotId": "D95D24xxxxE4F31A2697"
        }
    }
                        
  • Successful response
    {
        "code": 200,
        "data": {
            "gmtModified": 1517918765000,
            "activeTime": null,
            "deviceKey": "Kq7rgxxxxexwJh",
            "gmtCreate": 1500017648000,
            "productKey": "kQxxxxqA",
            "statusLast": null,
            "mac": null,
            "netAddress": null,
            "deviceSecret": "xxxxxxxxxxxxxxxxxxxxx",
            "iotId": "03iGXYVlxxxx9ccwgzHG",
            "name": "Kq7rgvxxxxexwJh",
            "tenantId": 7,
            "nickname": null,
            "sdkVersion": null,
            "sn": null,
            "thingType": "DEVICE",
            "region": "daily",
            "firmwareVersion": "1.0.0",
            "rbacTenantId": "ADSBCUYxxxx8327917",
            "ownerDomain": "kQxxxxqA",
            "status": 1
        },
        "message": "success",
        "localizedMsg": null
    }
                        

Get things in a batch

Definition

PathVersionDescriptioncloudToken required
/cloud/things/get1.0.2Batch Retrieve ObjectsYes

Request parameters

ParameterTypeRequiredDescription
productKeyStringYesUnique Product Identifier
statusIntYesThe device status.
  • 0: Inactive
  • 1: Online
  • 3: Offline
  • 8: Disabled
currentPageIntYespaged query
pageSizeIntYesThe number of entries per page.

Response parameters

ParameterTypeRequiredDescription
totalNumLongYesThe total number of records.
itemsListNoThe list of devices. The parameters in the list are the same as the response parameters of the Get the basic information of a thing operation.

Examples

  • Request example
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.2",
            "cloudToken": "token"
        },
        "params": {
            "productKey": "xxxxxxxxxxxxx",
            "status": 3,
            "currentPage": 1,
            "pageSize": 2
        }
    }
                        
  • Successful response
    {
        "code": 200,
        "data": [
            {
                "gmtModified": 1517922329000,
                "offset": null,
                "activeTime": null,
                "deviceKey": "d7Clxxxxu1Lp",
                "gmtCreate": 1501110001000,
                "productKey": "wxxxxtR",
                "statusLast": null,
                "mac": null,
                "netAddress": null,
                "iotId": "d7CllTxxx0010990700",
                "deviceSecret": "u98xxxxzhy/4cV1ThAEGxxxxf48Cf6YX+sqcP1Ky7",
                "name": "\r\n",
                "tenantId": 7,
                "nickname": null,
                "limit": null,
                "sdkVersion": null,
                "sn": null,
                "thingType": "DEVICE",
                "region": "daily",
                "firmwareVersion": null,
                "rbacTenantId": "ADSBCxxxx327917",
                "ownerDomain": "wLxxxxtR",
                "status": 1
            },
            {
                "gmtModified": 1517922329000,
                "offset": null,
                "activeTime": null,
                "deviceKey": "K1XuExxxxWgiQaq",
                "gmtCreate": 1501123511000,
                "productKey": "wxxxR",
                "statusLast": null,
                "mac": null,
                "netAddress": null,
                "iotId": "K1XuEDskxxxxxxxxq0010d93300",
                "deviceSecret": "bZxxxj/hZs27AJsNKg3xxxxxxxxxxxxjqcP1Ky7",
                "name": "K1XuxxxxgiQaq",
                "tenantId": 7,
                "nickname": null,
                "limit": null,
                "sdkVersion": null,
                "sn": null,
                "thingType": "DEVICE",
                "region": "daily",
                "firmwareVersion": null,
                "rbacTenantId": "ADSBCUYxxxx27918327917",
                "ownerDomain": "wLxxxxtR",
                "status": 1
            }
        ],
        "message": "success",
        "localizedMsg": null
    }
                        

Get the event timeline data of a thing

Description

PathVersionDescriptioncloudToken required
/cloud/thing/event/timeline/get1.0.2Gets the event timeline data of a thing. You can get data from the last year at most.Yes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNo (required under specific conditions)The unique identifier of the thing. This parameter is required if productKey and deviceName are empty.
productKeyStringNo (required under specific conditions)The unique identifier of the product. This parameter is required if iotId is empty.
deviceNameStringNo (required under specific conditions)The device name. This parameter is required if iotId is empty.
identifierStringYesProperty Identifier
eventTypeStringYesThe event type.
startLongYesThe start time of the timeline.
endLongYesThe end time of the timeline.
pageSizeIntYesThe number of entries to return on each page.
orderedBooleanYesThe query order.
  • true: Ascending
  • false: Descending

Response parameters

ParameterTypeDescription
eventCodeStringThe event identifier.
iotIdStringThe unique identifier of the thing.
eventNameStringThe event name.
eventTypeStringThe event type.
eventBodyObjectThe event parameters.
batchIdStringThe batch ID.
timestampLongThe time when the data was collected.

Examples

  • Request example
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.2",
            "cloudToken": "token"
        },
        "params": {
            "iotId": "D95D242941xxxxCCE4F31A2697",
            "identifier": "xxxx",
            "eventType": "xxxx",
            "start": 1517217645000,
            "end": 1517217645000,
            "pageSize": 10,
            "ordered": true
        }
    }
                        
  • Successful response
    {
        "code": 200,
        "message": "success",
        "localizedMsg": "",
        "data": {
            "items": [
                {
                    "eventCode": "Error",
                    "iotId": "YzqEnI5Dxxxxjjo0010840500",
                    "eventName": "Report error",
                    "eventType": "info",
                    "eventBody": {
                        "ErrorCode": 0
                    },
                    "batchId": "5ebc6a9c7dxxxxedde6d28c8fb3",
                    "timestamp": 1516342985261
                },
                {
                    "eventCode": "Error",
                    "iotId": "YzqEnI5Dxxxxxxxxjo0010840500",
                    "eventName": "Report error",
                    "eventType": "info",
                    "eventBody": {
                        "ErrorCode": 0
                    },
                    "batchId": "4a0b5a7ac8xxxxd5ff77456f1",
                    "timestamp": 1516342995305
                }
            ],
            "timestamp": 1516343075699
        }
    }
                        

Get the property timeline data of a thing

Description

PathVersionDescriptioncloudToken required
/cloud/thing/property/timeline/get1.0.2Gets the property timeline data of a thing. You can get data from the last year at most.Yes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNo (required under specific conditions)The unique identifier of the thing. This parameter is required if productKey and deviceName are empty.
productKeyStringNo (required under specific conditions)The unique identifier of the product. This parameter is required if iotId is empty.
deviceNameStringNo (required under specific conditions)The device name. This parameter is required if iotId is empty.
identifierStringYesThe property identifier.
startLongYesThe start time of the timeline.
endLongYesThe end time of the timeline.
pageSizeIntYesThe number of entries to return on each page. Maximum value: 200.
orderedBooleanYesThe query order.
  • true: Ascending
  • false: Descending

Response parameters

ParameterTypeDescription
iotidStringThe device identifier.
dataObjectThe timeline data of the device.
modifytimeLongThe time when the property was updated.
propertyStringThe property identifier.
batchIdStringThe batch ID.
timestampLongThe timestamp when the property was collected.

Examples

  • Request example
    {
        "id": "1509086454180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.2",
            "cloudToken": "token"
        },
        "params": {
            "iotId": "D95D24294xxxx1ECCE4F31A2697",
            "identifier": "xxxx",
            "start": 1517217645000,
            "end": 1517217645000,
            "pageSize": 10,
            "ordered": true
        }
    }
                        
  • Successful response
    {
      "code": 200,
      "message": "success",
      "localizedMsg": null,
      "data": {
        "items": [
          {
            "iotid": "xqxyZjSKzCxxxxvbv0O0010851c00",
            "data": 1.23,
            "modifytime": 1511812747287,
            "property": "LightVolt",
            "batchId": "2fc766c5e7xxxx3ed1f3e4b61803",
            "group": null,
            "timestamp": 1511812747245
          },
          {
            "iotid": "xqxyZjSKzxxxx0O0010851c00",
            "data": 1.24,
            "modifytime": 1511812747288,
            "property": "LightVolt",
            "batchId": "2fc766c5exxxx3ed1f3e4b61803",
            "group": null,
            "timestamp": 1511812747245
          }
        ],
        "timestamp": 1511812747245
      }
    }

Query the sub-device list of a gateway

Definition

PathVersionDescriptioncloudToken required
/living/cloud/device/subdevice/query1.0.0Performs a paged query for a list of sub-devices of a gateway.Yes

Request parameters

ParameterTypeRequiredDescription
iotIdStringNo (required under specific conditions)The unique identifier of the thing. This parameter is required if productKey or deviceName is empty.
productKeyStringNo (required under specific conditions)The key of the product. This parameter is required if iotId is empty.
deviceNameStringNo (required under specific conditions)The device name. This parameter is required if iotId is empty.
pageNoIntYesThe page number for the paged query.
pageSizeIntYesThe number of entries per page for the paged query. Maximum value: 20.

Response parameters

ParameterLevel-1 sub-parameterLevel-2 sub-parameterTypeDescription
dataThe list of sub-devices of the gateway.
totalLongThe total number of sub-devices.
pageNoIntThe current page number. Page numbers start from 1.
pageSizeIntPage size
itemsJSON ArrayDevice Certificate List
iotIdStringThe device ID.
deviceNameStringThe device name.
productKeyStringThe ProductKey of the device.
thingTypeStringThe type of the device:
  • VIRTUAL
  • WEB
  • APP
  • DEVICE
firmwareVersionStringThe firmware version number. This value is reported by the device. If the device has not reported this value, this parameter is not returned.
sdkVersionStringThe SDK version number.
statusIntThe device status.
  • 0: Inactive
  • 1: Online
  • 3: Offline
  • 8: Disabled
nodeTypeStringThe node type of the device:
  • DEVICE
  • GATEWAY
regionStringThe site where the device is located.
rbacTenantIdStringThe ID of the tenant to which the device belongs.
gmtCreateLongThe time when the record was created. This is the total number of milliseconds from 1970-01-01 to the present.
gmtModifiedLongThe time when the record was modified. This is the total number of milliseconds from 1970-01-01 to the present.

Examples

  • Request example
    {
        "id": "15090xxxx4180",
        "version": "1.0",
        "request": {
            "apiVer": "1.0.0",
            "cloudToken": "tokenxxxxxxxx"
        },
        "params": {
          "iotId":"CHWlsAQxxxxxMy4zs000101",
          "pageNo":1,
          "pageSize":10
        }
    }
  • Successful response
    {
        "code":200,
        "data":{
            "total":1,
            "pageNo":1,
            "pageSize":10,
            "items":[
                {
                    "iotId":"c2NBjWQUxxxxxxxxTPFu8000101",
                    "gmtModified":15789xxxx6000,
                    "thingType":"DEVICE",
                    "productKey":"a1HxxxxRiox",
                    "region":"cn-hangzhou",
                    "gmtCreate":15789xxxx6000,
                    "deviceName":"tesxxxxv0",
                    "rbacTenantId":"380D6988CxxxxxxxxxD9CBBDAC071",
                    "status":0
                }
            ]
        },
        "id":"3f757e2b-xxxx-xxxx-9926-b435bfe4bb6e"
    }