Creates a data forwarding rule for a specific topic.
Usage notes
When you call this operation, you must specify ProductKey in the request.
QPS limits
You can call this API operation up to 50 times per second per account.
The Resource Access Management (RAM) users of an Alibaba Cloud account share the quota of the account.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
Action | String | Yes | CreateRule | The operation that you want to perform. Set the value to CreateRule. |
Name | String | Yes | iot_test1 | The name of the data forwarding rule. The rule name must be 1 to 30 characters in length, and can contain letters, digits, underscores (_), and hyphens (-). |
IotInstanceId | String | No | iot-cn-0pp1n8t**** | The instance ID. You can view the instance ID on the Overview tab of the IoT Platform console. Important
For more information about instances, see Overview. |
Select | String | No | deviceName() as deviceName, items.Humidity.value as Humidity, items.Temperature.value as Temperature | The SQL SELECT statement that you want to execute. For more information, see SQL statements. Note This parameter specifies the fields in SELECT statements. For example, if the SELECT statement is |
ShortTopic | String | No | +/thing/event/property/post | The topic to which this rule is applied. The format is
|
Where | String | No | Temperature>35 | The condition that is used to trigger the rule. For more information about the rule, see SQL statements. Note This parameter specifies the fields in the WHERE clause. For example, if the WHERE statement is |
ProductKey | String | No | a1T27vz**** | The ProductKey of the product to which the rule applies. |
RuleDesc | String | No | rule test | The description of the rule. The description can be up to 100 characters in length. |
DataType | String | No | JSON | The format of the data that is processed based on the rule. The value of this parameter must be consistent with the format of the device data that you want to process. Valid values:
Note If you set this parameter to BINARY, you cannot set TopicType to 0 and cannot forward data to Tablestore and ApsaraDB RDS. |
TopicType | Integer | No | 1 |
|
ResourceGroupId | String | No | rg-acfmxazb4ph**** | The resource group ID. Important
|
Topic | String | No | /sys/g18l***/device1/thing/event/property/post | The complete topic to which the rule applies. If you specify this parameter, you do not need to specify ShortTopic and TopicType. |
In addition to the preceding operation-specific request parameters, you must specify common request parameters when you call this operation. For more information about common request parameters, see Common parameters.
To enable a rule, you must specify ProductKey, ShortTopic, and Select.
Response parameters
Parameter | Type | Example | Description |
Code | String | iot.system.SystemException | The error code returned if the request failed. For more information, see Error codes. |
ErrorMessage | String | A system exception occurred. | The error message returned if the request failed. |
RequestId | String | E4C0FF92-2A86-41DB-92D3-73B60310D25E | The request ID. |
RuleId | Long | 100000 | The rule ID. If the request was successful, the rules engine generates a rule ID for the rule. Note Keep the rule ID confidential. You may need to provide the rule ID if you want to call rule-related operations. |
Success | Boolean | true | Indicates whether the request was successful. Valid values:
|
Examples
Sample requests
https://iot.cn-shanghai.aliyuncs.com/?Action=CreateRule
&Name=iot_test1
&ProductKey=a1T27vz****
&ShortTopic=+/thing/event/property/post
&Select=deviceName() as deviceName, items.Humidity.value as Humidity, items.Temperature.value as Temperature
&RuleDesc=rule test
&DataType=JSON
&Where=Temperature>35
&TopicType=1
&<Common request parameters>
Sample success responses
XML
format
<CreateRuleResponse>
<RequestId>E4C0FF92-2A86-41DB-92D3-73B60310D25E</RequestId>
<RuleId>100000</RuleId>
<Success>true</Success>
</CreateRuleResponse>
JSON
format
{
"RequestId": "E4C0FF92-2A86-41DB-92D3-73B60310D25E",
"RuleId": 100000,
"Success": true
}
Error codes
For a list of error codes, see Service error codes.