• 沒有找到結果。

注意事项

HTTP 状态码

1.11 数据流转规则管理

1.11.2 创建规则触发条件

Internal server

error. 服务器内部错误 请联系华为工程师

分析解决。

IOTDA .00002 0

Decrypt IAM token

failed. IAM Token解析失 败

请联系华为工程师 分析解决。

1.11.2 创建规则触发条件

接口说明

应用服务器可调用此接口在物联网平台创建一条规则触发条件。

调试

您可以在API Explorer中调试该接口。

URI

请求方法 POST

URI /v5/iot/{project_id}/routing-rule/rules 传输协议 HTTPS

请求参数

名称 必选/可

类型 位置 说明

X-Auth-Token 必选 String Head

er 参数说明:用户Token。通过调用 IAM服务 获取IAM用户Token接口 获取,接口返回的响应消息头中

“X-Subject-Token”就是需要获 取的用户Token。简要的获取方法 样例请参见 Token认证。

Instance-Id 可选 String Head

er 参数说明:实例ID。物理多租下各 实例的唯一标识,一般华为云租户 无需携带该参数,仅在物理多租场 景下从管理面访问API时需要携带 该参数。

名称 必选/可 选

类型 位置 说明

project_i

d 必选 String Path 参数说明:项目ID。获取方法请参 见 获取项目ID。

rule_nam

e 可选 String Body 参数说明:规则名称。

取值范围:长度不超过256,只允 许中文、字母、数字、以及 _?'#().,&%@!-等字符的组合 descripti

on 可选 String Body 参数说明:用户自定义的规则描 述。

subject 必选 RoutingRule Subject Object

Body 参数说明:资源事件信息。

app_type 可选 String Body 参数说明:租户规则的生效范围,

默认GLOBAL,。

取值范围:

● GLOBAL:生效范围为租户级。

● APP:生效范围为资源空间级。

如果类型为APP,创建的规则生 效范围为携带的app_id指定的 资源空间,不携带app_id则创 建规则生效范围为默认资源空 间。

app_id 可选 String Body 参数说明:资源空间ID。。

取值范围:长度不超过36,只允许 字母、数字、下划线(_)、连接 符(-)的组合。

select 可选 String Body 参数说明:用户自定义sql select语 句,最大长度500,该参数仅供标 准版和企业版用户使用。

where 可选 String Body 参数说明:用户自定义sql where 语句,最大长度500,该参数仅供 标准版和企业版用户使用。

1-51 RoutingRuleSubject

名称 必选/可选 类型 说明

resource 必选 String 参数说明:资源名称。

取值范围:

● device:设备。

● device.property:设备属性。

● device.message:设备消息。

● device.message.status:设备消息 状态。

● device.status:设备状态。

● batchtask:批量任务。

● product:产品。

● device.command.status:设备异步 命令状态。

event 必选 String 参数说明:资源事件。

取值范围:与资源有关,不同的资源,

事件不同。event需要与resource关联 使用,具体的“resource:event”映 射关系如下:

● device:create(设备添加)

● device:delete(设备删除)

● device:update(设备更新)

● device.status:update (设备状态 变更)

● device.property:report(设备属 性上报)

● device.message:report(设备消 息上报)

● device.message.status:update

(设备消息状态变更)

● batchtask:update (批量任务状 态变更)

● product:create(产品添加)

● product:delete(产品删除)

● product:update(产品更新)

● device.command.status:update

(设备异步命令状态更新)

响应参数

名称 类型 说明

rule_id String 规则触发条件ID,用于唯一标识一个规则触发条 件,在创建规则条件时由物联网平台分配获得。

rule_name String 用户自定义的规则名称。

description String 用户自定义的规则描述。

subject RoutingRuleSu

bject Object 资源事件信息,即资源变化事件。

app_type String 租户规则的生效范围,取值如下:

● GLOBAL:生效范围为租户级

● APP:生效范围为资源空间级。

app_id String 资源空间ID

select String 用户自定义sql select语句,最大长度500,该参 数仅供标准版和企业版用户使用。

where String 用户自定义sql where语句,最大长度500,该参 数仅供标准版和企业版用户使用。

active Boolean 规则条件的状态是否为激活。

1-52 RoutingRuleSubject

名称 类型 说明

resource String 参数说明:资源名称。

取值范围:

● device:设备。

● device.property:设备属性。

● device.message:设备消息。

● device.message.status:设备消息状态。

● device.status:设备状态。

● batchtask:批量任务。

● product:产品。

● device.command.status:设备异步命令状 态。

名称 类型 说明

event String 参数说明:资源事件。

取值范围:与资源有关,不同的资源,事件不 同。event需要与resource关联使用,具体的

“resource:event”映射关系如下:

● device:create(设备添加)

● device:delete(设备删除)

● device:update(设备更新)

● device.status:update (设备状态变更)

● device.property:report(设备属性上报)

● device.message:report(设备消息上报)

● device.message.status:update(设备消息状 态变更)

● batchtask:update (批量任务状态变更)

● product:create(产品添加)

● product:delete(产品删除)

● product:update(产品更新)

● device.command.status:update(设备异步 命令状态更新)

请求示例

POST https://{Endpoint}/v5/iot/{project_id}/routing-rule/rules Content-Type: application/json

X-Auth-Token: ********

Instance-Id: ********

{ "rule_name" : "rulename", "description" : "description", "subject" : {

"resource" : "device", "event" : "create"

}, "app_type" : "GLOBAL",

"app_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce0", "select" : "*",

"where" : "product_id='d89c-44dd-8265-b1653d951ce0'"

}

响应示例

Status Code: 201 Created

Content-Type: application/json

{ "rule_id" : "5bcaddda-75bf-4623-8c8d-26175c41fcca", "rule_name" : "rulename",

"description" : "description", "subject" : {

"resource" : "device",

"event" : "create"

}, "app_type" : "GLOBAL",

"app_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce0", "select" : "*",

"where" : "product_id='d89c-44dd-8265-b1653d951ce0'", "active" : false

}

错误码

HTTP

状态码 错误码 错误码英文描述 错误码中文描述 处理建议 400 IOTDA

.00100 4

AppId is not in

request header. appId未在请求头设 置

The resource model does not exist.

The resource does

not match event. resource和event不 匹配

The rule with this same condition is already exist.

该规则条件的规则 已经存在

规则已存在, 无需 重复注册。

403 IOTDA .00002 1

Operation not allowed. User not found by IAM token or the authorized user has not subscribed IOTDA service.

没有找到IAM Token所对应的用户 信息或该用户没有 订阅设备接入服务

(IOTDA)

请排查IAM Token 所在用户是否订阅

Operation not allowed. The user does not have the permission

The application

does not exist. 该应用不存在 请确定是否已在平 台注册应用并检查 应用ID是否正确。

HTTP

Operation not allowed. The parameter 'app_id' is not carried, and the authorized user has more than one applications.

Include the

parameter 'app_id', or contact Huawei technical support engineers to merge application data.

Operation not allowed.

Application not found by

authorized user or the authorized user has no application.

Operation not allowed. The application does not belong to the authorized user.

应用与用户信息不

The number of rules has reached the upper limit.

规则数量已达到上 限

请删除多余的规则 后重试。

500 IOTDA .00000 1

Internal server

error. 服务器内部错误 请联系华为工程师

分析解决。

IOTDA .00002 0

Decrypt IAM token

failed. IAM Token解析失 败

请联系华为工程师 分析解决。