Create Message Rules


Create message rules.

A user or user group can be associated with up to 6 message rules.

Request Format


POST https://{apigw-address}/app-portal-service/v2.2/message-service/rule/create

Request Parameters (URI)


Name

Location (Path/Query)

Required/Optional

Data Type

Description

orgId

Query

Required

String

OU ID. How to get orgId >>

Request Parameters (Header)


Name

Required/Optional

Data Type

Description

Authorization

Optional

String

The access token generated after the user logs in and selects the OU, represented by Bearer Token, is in the form of Bearer {your token}. You can call the Log In or Refresh Access Token API to obtain the access token.

  • If this parameter is not specified, the creator of the rules will be considered as the application.

  • If this parameter is specified, the creator of the rules will be considered as the user which the access token belongs to. The OU for obtaining the Access Token should be consistent with the value of the request parameter orgId.

Request Parameters (Body)


Name

Required/Optional

Data Type

Description

appId

Required

String

The access key of the application. How to get Access Key >>

rules

Required

rulesDTO Struct

The content of message rules. rulesDTO Struct >>

relations

Optional

relationsDTO Struct

The users or user groups associated with the rules. relationsDTO Struct >>

rulesDTO Struct


Name

Required/Optional

Data Type

Description

ruleName

Required

String

The rule name.

messageRule

Required

Object

Conditions that trigger messages based on specific marks, such as assets, users, or event types. Each rule must contain 1 to 6 marks. Only when all marks in the rule are satisfied can the message be triggered. Marks are key-value pairs in the form of "markN": ["value1", "value2", ...] or "markN": null, where:

  • Key: must be in the markN format, such as mark1, mark2, where N is a positive integer. Keys are unique within a rule.

  • Value: a list of strings (or null) representing the associated entities, such as site ID, user ID, etc. Each value can be up to 400 characters long. If multiple entities are listed in a value, an event that matches any of the entities satisfies the mark.

For example, "messageRule": {"mark1": ["siteA", "siteB"], "mark2": ["user123"]} means that the rule will be triggered and a message will be sent to the users or user groups when the event is associated with siteA or siteB, and is also associated with user123.

isEnable

Required

String

Whether to enable the message rule. The following values ​​are supported:

  • 0 means disabled.

  • 1 means enabled.

Enabled by default.

relationsDTO Struct


Name

Required/Optional

Data Type

Description

type

Optional, required if relations structure is specified

Integer

The type of object the rule is associated with. If you create multiple rules, all rules will be associated with this object type. The following values ​​are supported:

  • 0 for users.

  • 1 for user groups.

identifiers

Optional, required if relations structure is specified

List

The list of user IDs or user group IDs. If you create multiple rules, all rules will be associated with the users or user groups. A user or user group can be associated with up to 6 message rules.

Response Parameters


Name

Data Type

Description

data

List

The message rule IDs.

Error Codes


Error Code

Description

31400

OU ID is empty.

31404

Possible reasons: OU does not exist, application does not exist, OU does not obtain application, user or user group does not exist, etc.

31600

The message rule content is abnormal.

31601

The number of message rules exceeds the limit.

31602

The number of marks in the request parameter messageRule exceeds the limit.

31604

At least one mark in the request parameter messageRule is required.

31607

Organization structure error.

Samples

Request Sample


url: https://{apigw-address}/app-portal-service/v2.2/message-service/rule/create?orgId=your_org_id

method: POST

requestBody:
{
    "appId": "your_access_key",
    "rules": [
        {
            "isEnable": 0,
            "ruleName": "your_rule_name_1",
            "messageRule": {
                "mark1": ["siteA","siteB"],
                "mark2": ["deviceA","deviceB"],
                "mark3": ["fault"],
                "mark4": [""],
                "mark5": null
            }
        },
        {
            "isEnable": 0,
            "ruleName": "your_rule_name_2",
            "messageRule": {
                "mark1": ["siteA","siteB"],
                "mark2": ["deviceA","deviceB"],
                "mark3": ["fault"],
                "mark4": [""],
                "mark5": null
            }
        }
    ],
    "relations": [
        {
            "type": 0,
            "identifiers": ["your_id_1","your_id_2"]
        },
        {
            "type": 1,
            "identifiers": ["your_id_3"]
        }
    ]
}

Return Sample


{
    "code": 0,
    "message": "OK",
    "data": ["your_message_rule_id_1","your_message_rule_id_2"]
}