Create a Rule Action
Function
This API is used by an application to create a rule action on the IoT platform.
Debugging
You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.
URI
POST /v5/iot/{project_id}/routing-rule/actions
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Parameter description: project ID. For details about how to obtain the project ID, see Obtaining a Project ID. |
Request 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. X-Subject-Token in the response header returned by the API is the desired user token. For details about how to obtain the token, see Token Authentication. |
Instance-Id |
No |
String |
Parameter description: instance ID. This parameter is required only when the API is called from the management plane in the physical multi-tenant scenario. You can log in to the IoTDA console and choose Overview in the navigation pane to view the instance ID. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
rule_id |
Yes |
String |
Parameter description: unique ID of a rule triggering condition. The value is allocated by the platform during rule creation. Value: The value can contain a maximum of 36 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. |
channel |
Yes |
String |
Parameter description: type of the rule action. Options:
|
channel_detail |
Yes |
ChannelDetail object |
Parameter description: channel parameters. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
http_forwarding |
No |
HttpForwarding object |
Parameter description: HTTP server message forwarding. This parameter is mandatory when channel is set to HTTP_FORWARDING. |
dis_forwarding |
No |
DisForwarding object |
** Parameter description**: DIS service message forwarding. This parameter is mandatory when channel is set to DIS_FORWARDING. |
obs_forwarding |
No |
ObsForwarding object |
** Parameter description**: OBS service message forwarding. This parameter is mandatory when channel is set to OBS_FORWARDING. |
amqp_forwarding |
No |
AmqpForwarding object |
Parameter description: AMQP service message forwarding. This parameter is mandatory when channel is set to AMQP_FORWARDING. |
dms_kafka_forwarding |
No |
DmsKafkaForwarding object |
Parameter description: Kafka message forwarding. This parameter is mandatory when channel is set to DMS_KAFKA_FORWARDING. |
mysql_forwarding |
No |
MysqlForwarding object |
Parameter description: MySQL message forwarding. This parameter is mandatory when channel is set to MYSQL_FORWARDING. |
influxdb_forwarding |
No |
InfluxDBForwarding object |
Parameter description: InfluxDB forwarding configuration parameters. This parameter is mandatory when channel is set to INFLUXDB_FORWARDING. |
functiongraph_forwarding |
No |
FunctionGraphForwarding object |
Parameter description: FunctionGraph service message forwarding. This parameter is mandatory when channel is set to FUNCTIONGRAPH_FORWARDING. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
url |
Yes |
String |
Parameter description: IP address of the HTTP server for receiving data that meets the rule triggering condition. HTTP is an insecure non-encrypted data transmission mode. You are advised to use HTTPS, which is more secure. Minimum: 1 Maximum: 256 |
cert_id |
No |
String |
Parameter description: certificate ID. For details about how to obtain a certificate ID, see step 3 in Loading the CA Certificate. Minimum: 1 Maximum: 64 |
cn_name |
No |
String |
Parameter description: If sni_enable is set to true, this parameter is mandatory and the value is the domain name of the server certificate, for example, domain:8443. If sni_enable is set to false, this parameter is left blank by default. Minimum: 1 Maximum: 64 |
sni_enable |
No |
Boolean |
Parameter description: The HTTPS server and client must support this function. The default value is false. If this parameter is set to true, the HTTPS client needs to carry cn_name when initiating a request. The HTTPS server returns the corresponding certificate based on cn_name. If this parameter is set to false, this function is disabled. |
signature_enable |
No |
Boolean |
Parameter description: whether to enable a signature. The token takes effect only when this parameter is set to true. You are advised to set this parameter to true to use the token signature to check whether messages are from the platform. |
token |
No |
String |
Parameter description: Token used to generate a signature. The client can use the token to generate a signature based on rules and compare the signature with that carried in the push message for security verification. Value: The value can contain 3 to 32 characters. Only letters and digits are allowed. For details, see [Token-based IoT Platform Authentication for HTTP/HTTPS Subscription/Push]. Minimum: 3 Maximum: 32 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
region_name |
Yes |
String |
Parameter description: region where the DIS service is deployed. Minimum: 1 Maximum: 256 |
project_id |
Yes |
String |
Parameter description: ID of the project to which the DIS service belongs. Minimum: 1 Maximum: 256 |
stream_name |
No |
String |
Parameter description: DIS stream name. Either stream_id or stream_name must be carried. If both parameters are carried, stream_id is used. Minimum: 1 Maximum: 256 |
stream_id |
No |
String |
Parameter description: DIS stream ID. Either stream_id or stream_name must be carried. If both parameters are carried, stream_id is used. Minimum: 1 Maximum: 256 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
region_name |
Yes |
String |
Parameter description: region where the OBS service is deployed. Minimum: 1 Maximum: 256 |
project_id |
Yes |
String |
Parameter description: ID of the project to which the OBS service belongs. Minimum: 1 Maximum: 256 |
bucket_name |
Yes |
String |
Parameter description: OBS bucket name. Minimum: 1 Maximum: 256 |
location |
No |
String |
Parameter description: region where the OBS bucket is deployed. Minimum: 1 Maximum: 256 |
file_path |
No |
String |
Parameter description: custom directory to store files that will be dumped to OBS. Different directory levels are separated by slashes (/). The directory cannot start or end with a slash (/) or contain two or more consecutive slashes (/). Value: The value can contain a maximum of 256 characters. Only letters (a–z and A–Z), digits (0–9), underscores (_), hyphens (-), slashes (/), and braces ({}) are allowed. Braces can be used only for template parameters. Template parameters:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
queue_name |
Yes |
String |
Parameter description: AMQP queue for receiving data that meets the rule triggering condition. Minimum: 8 Maximum: 256 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
region_name |
Yes |
String |
Parameter description: region where the Kafka service is deployed. Minimum: 1 Maximum: 256 |
project_id |
Yes |
String |
Parameter description: ID of the project to which the Kafka service belongs. Minimum: 1 Maximum: 256 |
addresses |
Yes |
Array of SupportPrivateLinkNetAddress objects |
Parameter description: list of addresses for Kafka message forwarding. |
topic |
Yes |
String |
Parameter description: topic associated with the message to be forwarded to Kafka. Minimum: 1 Maximum: 256 |
username |
No |
String |
Parameter description: username associated with the message to be forwarded to Kafka. Minimum: 1 Maximum: 256 |
password |
No |
String |
Parameter description: password associated with the message to be forwarded to Kafka. Minimum: 1 Maximum: 256 |
mechanism |
No |
String |
Parameter description: SASL authentication mechanism associated with the message to be forwarded to Kafka. Options:
|
security_protocol |
No |
String |
Parameter description: Kafka transmission security protocol. If this parameter is left blank, the default value SASL_SSL is used. This parameter does not take effect when mechanism is set to PAAS or left empty. Options:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
ip |
No |
String |
Parameter description: IP address of the service. |
port |
No |
Integer |
Parameter description: Port number of the service. Minimum: 0 Maximum: 65535 |
domain |
No |
String |
Parameter description: Domain name of the service. Minimum: 4 Maximum: 255 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
address |
Yes |
NetAddress object |
List of addresses to which the message is forwarded to ROMA. |
db_name |
Yes |
String |
Parameter description: name of the MySQL database to be connected. Value: The value can contain a maximum of 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. |
username |
Yes |
String |
Parameter description: username of the MySQL database to be connected. Minimum: 1 Maximum: 256 |
password |
Yes |
String |
Parameter description: password of the MySQL database to be connected. Minimum: 1 Maximum: 256 |
enable_ssl |
No |
Boolean |
Parameter description: Whether the client uses SSL to connect to the server. The default value is true. If the value is false, the insecure non-encrypted data transmission mode is used. You are advised to use the SSL mode. Default: true |
table_name |
Yes |
String |
Parameter description: table name of the MySQL database. Minimum: 1 Maximum: 64 |
column_mappings |
Yes |
Array of ColumnMapping objects |
** Parameter description**: list of mappings between MySQL databases and the forwarding data. A maximum of 32 mappings are supported. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
address |
Yes |
NetAddress object |
Parameter description: addresses for InfluxDB message forwarding. |
db_name |
Yes |
String |
Parameter description: name of the InfluxDB database to be connected. The database will be automatically created if it does not exist. Minimum: 1 Maximum: 64 |
username |
Yes |
String |
Parameter description: username of the InfluxDB database to be connected. Minimum: 1 Maximum: 256 |
password |
Yes |
String |
Parameter description: password of the InfluxDB database to be connected. Minimum: 1 Maximum: 256 |
measurement |
Yes |
String |
Parameter description: measurement of the InfluxDB database. The measurement will be automatically created if it does not exist. Minimum: 1 Maximum: 64 |
column_mappings |
Yes |
Array of ColumnMapping objects |
** Parameter description**: list of mappings between InfluxDB databases and the forwarding data. A maximum of 32 mappings are supported. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
ip |
No |
String |
Parameter description: IP address of the service. |
port |
No |
Integer |
Parameter description: port number of the service. Minimum: 0 Maximum: 65535 |
domain |
No |
String |
Parameter description: domain name of the service. Minimum: 4 Maximum: 255 |
Response Parameters
Status code: 201
Parameter |
Type |
Description |
---|---|---|
action_id |
String |
Unique rule ID, which is allocated by the platform during rule creation. You do not need to carry this parameter when creating a rule. |
rule_id |
String |
ID of the rule triggering condition corresponding to the rule action. |
app_id |
String |
Resource space ID. |
channel |
String |
Rule action type. Options:
|
channel_detail |
ChannelDetail object |
Channel configuration details. |
Parameter |
Type |
Description |
---|---|---|
http_forwarding |
HttpForwarding object |
Parameter description: HTTP server message forwarding. This parameter is mandatory when channel is set to HTTP_FORWARDING. |
dis_forwarding |
DisForwarding object |
** Parameter description**: DIS service message forwarding. This parameter is mandatory when channel is set to DIS_FORWARDING. |
obs_forwarding |
ObsForwarding object |
** Parameter description**: OBS service message forwarding. This parameter is mandatory when channel is set to OBS_FORWARDING. |
amqp_forwarding |
AmqpForwarding object |
Parameter description: AMQP service message forwarding. This parameter is mandatory when channel is set to AMQP_FORWARDING. |
dms_kafka_forwarding |
DmsKafkaForwarding object |
Parameter description: Kafka message forwarding. This parameter is mandatory when channel is set to DMS_KAFKA_FORWARDING. |
mysql_forwarding |
MysqlForwarding object |
Parameter description: MySQL message forwarding. This parameter is mandatory when channel is set to MYSQL_FORWARDING. |
influxdb_forwarding |
InfluxDBForwarding object |
Parameter description: InfluxDB forwarding configuration parameters. This parameter is mandatory when channel is set to INFLUXDB_FORWARDING. |
functiongraph_forwarding |
FunctionGraphForwarding object |
Parameter description: FunctionGraph service message forwarding. This parameter is mandatory when channel is set to FUNCTIONGRAPH_FORWARDING. |
Parameter |
Type |
Description |
---|---|---|
url |
String |
Parameter description: IP address of the HTTP server for receiving data that meets the rule triggering condition. HTTP is an insecure non-encrypted data transmission mode. You are advised to use HTTPS, which is more secure. Minimum: 1 Maximum: 256 |
cert_id |
String |
Parameter description: certificate ID. For details about how to obtain a certificate ID, see step 3 in Loading the CA Certificate. Minimum: 1 Maximum: 64 |
cn_name |
String |
Parameter description: If sni_enable is set to true, this parameter is mandatory and the value is the domain name of the server certificate, for example, domain:8443. If sni_enable is set to false, this parameter is left blank by default. Minimum: 1 Maximum: 64 |
sni_enable |
Boolean |
Parameter description: The HTTPS server and client must support this function. The default value is false. If this parameter is set to true, the HTTPS client needs to carry cn_name when initiating a request. The HTTPS server returns the corresponding certificate based on cn_name. If this parameter is set to false, this function is disabled. |
signature_enable |
Boolean |
Parameter description: whether to enable a signature. The token takes effect only when this parameter is set to true. You are advised to set this parameter to true to use the token signature to check whether messages are from the platform. |
token |
String |
Parameter description: Token used to generate a signature. The client can use the token to generate a signature based on rules and compare the signature with that carried in the push message for security verification. Value: The value can contain 3 to 32 characters. Only letters and digits are allowed. For details, see [Token-based IoT Platform Authentication for HTTP/HTTPS Subscription/Push]. Minimum: 3 Maximum: 32 |
Parameter |
Type |
Description |
---|---|---|
region_name |
String |
Parameter description: region where the DIS service is deployed. Minimum: 1 Maximum: 256 |
project_id |
String |
Parameter description: ID of the project to which the DIS service belongs. Minimum: 1 Maximum: 256 |
stream_name |
String |
Parameter description: DIS stream name. Either stream_id or stream_name must be carried. If both parameters are carried, stream_id is used. Minimum: 1 Maximum: 256 |
stream_id |
String |
Parameter description: DIS stream ID. Either stream_id or stream_name must be carried. If both parameters are carried, stream_id is used. Minimum: 1 Maximum: 256 |
Parameter |
Type |
Description |
---|---|---|
region_name |
String |
Parameter description: region where the OBS service is deployed. Minimum: 1 Maximum: 256 |
project_id |
String |
Parameter description: ID of the project to which the OBS service belongs. Minimum: 1 Maximum: 256 |
bucket_name |
String |
Parameter description: OBS bucket name. Minimum: 1 Maximum: 256 |
location |
String |
Parameter description: region where the OBS bucket is deployed. Minimum: 1 Maximum: 256 |
file_path |
String |
Parameter description: custom directory to store files that will be dumped to OBS. Different directory levels are separated by slashes (/). The directory cannot start or end with a slash (/) or contain two or more consecutive slashes (/). Value: The value can contain a maximum of 256 characters. Only letters (a–z and A–Z), digits (0–9), underscores (_), hyphens (-), slashes (/), and braces ({}) are allowed. Braces can be used only for template parameters. Template parameters:
|
Parameter |
Type |
Description |
---|---|---|
queue_name |
String |
Parameter description: AMQP queue for receiving data that meets the rule triggering condition. Minimum: 8 Maximum: 256 |
Parameter |
Type |
Description |
---|---|---|
region_name |
String |
Parameter description: region where the Kafka service is deployed. Minimum: 1 Maximum: 256 |
project_id |
String |
Parameter description: ID of the project to which the Kafka service belongs. Minimum: 1 Maximum: 256 |
addresses |
Array of SupportPrivateLinkNetAddress objects |
Parameter description: list of addresses for Kafka message forwarding. |
topic |
String |
Parameter description: topic associated with the message to be forwarded to Kafka. Minimum: 1 Maximum: 256 |
username |
String |
Parameter description: username associated with the message to be forwarded to Kafka. Minimum: 1 Maximum: 256 |
password |
String |
Parameter description: password associated with the message to be forwarded to Kafka. Minimum: 1 Maximum: 256 |
mechanism |
String |
Parameter description: SASL authentication mechanism associated with the message to be forwarded to Kafka. Options:
|
security_protocol |
String |
Parameter description: Kafka transmission security protocol. If this parameter is left blank, the default value SASL_SSL is used. This parameter does not take effect when mechanism is set to PAAS or left empty. Options:
|
Parameter |
Type |
Description |
---|---|---|
ip |
String |
Parameter description: IP address of the service. |
port |
Integer |
Parameter description: Port number of the service. Minimum: 0 Maximum: 65535 |
domain |
String |
Parameter description: Domain name of the service. Minimum: 4 Maximum: 255 |
Parameter |
Type |
Description |
---|---|---|
address |
NetAddress object |
List of addresses to which the message is forwarded to ROMA. |
db_name |
String |
Parameter description: name of the MySQL database to be connected. Value: The value can contain a maximum of 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. |
username |
String |
Parameter description: username of the MySQL database to be connected. Minimum: 1 Maximum: 256 |
password |
String |
Parameter description: password of the MySQL database to be connected. Minimum: 1 Maximum: 256 |
enable_ssl |
Boolean |
Parameter description: Whether the client uses SSL to connect to the server. The default value is true. If the value is false, the insecure non-encrypted data transmission mode is used. You are advised to use the SSL mode. Default: true |
table_name |
String |
Parameter description: table name of the MySQL database. Minimum: 1 Maximum: 64 |
column_mappings |
Array of ColumnMapping objects |
** Parameter description**: list of mappings between MySQL databases and the forwarding data. A maximum of 32 mappings are supported. |
Parameter |
Type |
Description |
---|---|---|
address |
NetAddress object |
Parameter description: addresses for InfluxDB message forwarding. |
db_name |
String |
Parameter description: name of the InfluxDB database to be connected. The database will be automatically created if it does not exist. Minimum: 1 Maximum: 64 |
username |
String |
Parameter description: username of the InfluxDB database to be connected. Minimum: 1 Maximum: 256 |
password |
String |
Parameter description: password of the InfluxDB database to be connected. Minimum: 1 Maximum: 256 |
measurement |
String |
Parameter description: measurement of the InfluxDB database. The measurement will be automatically created if it does not exist. Minimum: 1 Maximum: 64 |
column_mappings |
Array of ColumnMapping objects |
** Parameter description**: list of mappings between InfluxDB databases and the forwarding data. A maximum of 32 mappings are supported. |
Parameter |
Type |
Description |
---|---|---|
ip |
String |
Parameter description: IP address of the service. |
port |
Integer |
Parameter description: port number of the service. Minimum: 0 Maximum: 65535 |
domain |
String |
Parameter description: domain name of the service. Minimum: 4 Maximum: 255 |
Example Requests
-
Creates a rule action and pushes it to the HTTP server.
POST https://{endpoint}/v5/iot/{project_id}/routing-rule/actions { "rule_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce0", "channel" : "HTTP_FORWARDING", "channel_detail" : { "http_forwarding" : { "url" : "http://host:port/callbackurltest" } } }
-
Creates a rule action and pushes it to OBS.
POST https://{endpoint}/v5/iot/{project_id}/routing-rule/actions { "rule_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce0", "channel" : "OBS_FORWARDING", "channel_detail" : { "obs_forwarding" : { "file_path" : "yourPath", "project_id" : "yourProjectId", "bucket_name" : "yourBucket_name", "region_name" : "yourRegion" } } }
-
Creates a rule action and pushes it to an AMQP queue.
POST https://{endpoint}/v5/iot/{project_id}/routing-rule/actions { "rule_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce0", "channel" : "AMQP_FORWARDING", "channel_detail" : { "amqp_forwarding" : { "queue_name" : "yourQueueName" } } }
-
Creates a rule action and pushes it to a MySQL database.
POST https://{endpoint}/v5/iot/{project_id}/routing-rule/actions { "rule_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce0", "channel" : "MYSQL_FORWARDING", "channel_detail" : { "mysql_forwarding" : { "address" : { "ip" : "yourIp", "port" : 3306 }, "username" : "userName", "password" : "passworld", "db_name" : "yourDBName", "table_name" : "yourTableName", "enable_ssl" : true, "column_mappings" : [ { "column_name" : "serviceId", "json_key" : "notify_data.body.services[0].service_id" } ] } } }
Example Responses
Status code: 201
Created
{ "action_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce1", "rule_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce0", "app_id" : "1a7ffc5cd89c44dd8265b1653d951ce0", "channel" : "HTTP_FORWARDING", "channel_detail" : { "http_forwarding" : { "url" : "http://host:port/callbackurltest" } } }
Status Codes
Status Code |
Description |
---|---|
201 |
Created |
400 |
Bad Request |
401 |
Unauthorized |
403 |
Forbidden |
404 |
not found |
500 |
Internal Server Error |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot