V2.1 Search Command


按照筛选条件查询云端向设备发送的指令信息。

如果你在使用 API 批量更新相关命令信息后调用当前 API,建议两次调用间隔 2 秒左右,以免获取到未更新数据。


该 API 支持在 EnOS 2.1.0 及以上环境中使用。

请求格式

POST https://{apigw-address}/connect-service/v2.1/commands?action=search

请求参数(URI)

备注

以下非必需字段中,必须提供 assetIdproductKey + deviceKey 的组合,用于指定设备。

名称

位置(Path/Query)

必需/可选

数据类型

描述

orgId

Query

必需

String

设备所属的 OU ID。如何获取 orgId 信息>>

assetId

Query

可选(见上述注解)

String

设备的 asset ID。如何获取 assetId 信息>>

productKey

Query

可选(见上述注解)

String

设备的 product key,需与 deviceKey 一起使用。如何获取设备的三元组信息>>

deviceKey

Query

可选(见上述注解)

String

设备的 device key,需与 productKey 一起使用。如何获取设备的三元组信息>>

请求参数(Body)

名称

必需/可选

数据类型

描述

expression

可选

String

查询表达式,支持类 SQL 的查询。目前支持查询的字段是 statecommandNamecreateTime

  • state 支持等于(=)运算符。

  • commandName.default 支持模糊匹配,必须提供 locale,如 commandName.zh_CN 或 commandName.en_US、commandName.defaultValue。

  • createTime 支持用 < 和 >= 运算符来指定时间范围。指定的时间需要采用 YYYY-MM-DD HH:mm:ss 的格式,如:2019-04-17 10:30:00

如何使用查询表达式>>

pagination

可选

Pagination 请求结构体

分页参数。如未指定,默认每页 100 条。为获得最佳性能,建议每页不超过 50 条。不支持使用 sorters 参数对结果进行排序,查询结果按照 createTime,最近创建的靠前排列。Pagination 请求结构体>>

projection

可选

Projection 结构体

指定对返回结果的裁剪。对于符合条件的搜索仅返回符合条件的字段,不设置则默认返回全部字段。Projection 参数如何对结果集做裁剪>>

响应参数

名称

数据类型

描述

data

Command 结构体数组

有关 Command 结构体的定义,参见 Command 结构体

Command 结构体

示例 1

请求示例

url: https://{apigw-address}/connect-service/v2.1/commands?action=search&deviceKey=yourDeviceKey&productKey=yourProductKey&orgId=yourOrgId
method: POST
requestBody:
{
    "expression":"state = 2",
    "pagination":{
        "pageNo":1,
        "pageSize":5
    }
}

返回示例

{
  "code": 0,
  "msg": "OK",
  "requestId": "df57e058-0d8b-4700-9e38-ef30132c155f",
  "data": [
    {
      "commandId": "2322417636630765568",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688731159",
      "createLocaltime": "2019-08-13 09:32:11",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 30,
      "pendingTtl": 100,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417598073053184",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688726563",
      "createLocaltime": "2019-08-13 09:32:06",
      "commandType": 2,
      "commandName": {
        "defaultValue": "service522",
        "i18nValue": {
          "en_US": "service522"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "service522",
      "inputData": {
        "service_input": 555
      },
      "outputData": null
    },
    {
      "commandId": "2322417559066025984",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": 1565688721913,
      "createLocaltime": "2019-08-13 09:32:01",
      "commandType": 2,
      "commandName": {
        "defaultValue": "service522",
        "i18nValue": {
          "en_US": "service522"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "service522",
      "inputData": {
        "service_input": 555
      },
      "outputData": null
    },
    {
      "commandId": "2322417537678745600",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": 1565688719363,
      "createLocaltime": "2019-08-13 09:31:59",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417518334615552",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": 1565688717057,
      "createLocaltime": "2019-08-13 09:31:57",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    }
  ],
  "pagination": {
    "sortedBy": [
      {
        "field": "createDate",
        "order": "DESC"
      }
    ],
    "pageNo": 1,
    "pageSize": 5,
    "totalSize": 547
  }
}

示例 2

请求示例

url: https://{apigw-address}/connect-service/v2.1/commands?action=search&deviceKey=yourDeviceKey&productKey=yourProductKey&orgId=yourOrgId
method: POST
requestBody:
{
  "expression": "commandName.zh_CN like \"Int_value\" AND createTime >= \"2019-08-13 09:00:00\"",
  "pagination": {
    "pageNo": 1,
    "pageSize": 5
  }
}

返回示例

{
  "code": 0,
  "msg": "OK",
  "requestId": "051ab2c9-5de4-4c05-9731-042475234267",
  "data": [
    {
      "commandId": "2322417698664521728",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688738554",
      "createLocaltime": "2019-08-13 09:32:18",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 30,
      "pendingTtl": 0,
      "state": 6,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417676665921536",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688735932",
      "createLocaltime": "2019-08-13 09:32:15",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 30,
      "pendingTtl": 0,
      "state": 6,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417636630765568",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688731159",
      "createLocaltime": "2019-08-13 09:32:11",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 30,
      "pendingTtl": 100,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417537678745600",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688719363",
      "createLocaltime": "2019-08-13 09:31:59",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417518334615552",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688717057",
      "createLocaltime": "2019-08-13 09:31:57",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    }
  ],
  "pagination": {
    "sortedBy": [
      {
        "field": "createDate",
        "order": "DESC"
      }
    ],
    "pageNo": 1,
    "pageSize": 5,
    "totalSize": 6
  }
}

SDK 示例


你可以在 Github 上获取接入服务的 SDK 示例: