Create rule
    • PDF

    Create rule

    • PDF

    Article Summary

    Summary

    Creates a rule.

    Request

    Request URL

    POST {CLOUD_IOT_CORE_API_URL}/rules
    
    Content-Type: application/json; charset=utf-8
    x-ncp-apigw-timestamp: {Timestamp}
    x-ncp-iam-access-key: {Sub Account Access Key}
    x-ncp-apigw-signature-v2: {API Gateway Signature}
    

    Request body

    {
            "rule": {
                "name": "string",
                "description": "string",
                "query": "string"
            },
            "actions": {
                "matchActionList": [
                    {
                        "relatedProduct": "string",
                        "relatedProductAction": "json"
                    }
                ],
                "errorAction": {
                    "relatedProduct": "string",
                    "relatedProductAction": "json"
                }
            }
        }
    
    CategoryRequired statusTypeRestrictionsDescription
    ruleYesrule
    rule.nameYesstringLess than 128 characters. Only lower and upper English letters, numbers, -, and _ are allowed.Name of the rule
    rule.descriptionNostringLess than 255 charactersDescription of the rule
    rule.queryYesstringrule query rulesrule query
    actionsYesAction
    matchedActionListYesAction to take when rule query is satisfied
    actions.matchedActionList[].relateProductYesstringRefer to relatedProduct belowType of action to be linked
    actions.matchedActionList[].relateProductActionYesjsonRefer to relatedProductAction belowDetails of action to be linked
    errorActionNoWhen linking error actions, the relatedProduct, relatedProductAction fields are mandatoryError action
    errorAction.relateProductNostringRefer to relatedProduct belowType of action to be linked
    errorAction.relateProductActionNojsonRefer to relatedProductAction belowDetails of action to be linked

    relatedProduct

    relatedProductAction name
    REPUBLISHRepublish as a specified topic
    CLOUD_FUNCTIONSTransfer data to Cloud Functions

    relatedProductAction

    - REPUBLISH

    {
            "topic":  "string"
    }
    
    CategoryRequired statusTypeRestrictionsDescription
    topicYesstringTopic limitationsRepublish topic

    - CLOUD_FUNCTIONS

    {
            "name":  "string",
            "batchTime": "integer"
    }
    
    CategoryRequired statusTypeRestrictionsDescription
    nameYesstringName of IoT trigger registered in Cloud functions
    batchTimeNointegerMin: 5, Max: 600Cloud Functions batch Interval Time(Seconds)

    Request example

    {
        "rule": {
            "name": "lux",
            "description": "turn off",
            "query": "select lux, bulb_id from \"myhome100/abc/+/abc\" where lux > -1"
        },
        "actions": {
            "matchActionList": [
                {
                    "relatedProduct": "REPUBLISH",
                    "relatedProductAction": {
                        "topic": "republish_a"
                    }
                }
            ],
            "errorAction": {
                "relatedProduct": "REPUBLISH",
                "relatedProductAction": {
                    "topic": "republish_a"
                }
            }
        }
    }
    

    Response

    Response body

    {
        "status": "string",
        "body": {
            "rule": {
                "name": "string",
                "description": "string",
                "status": "string",
                "query": "string",
                "modifyTime": "localDateTime",
                "registerTime": "localDateTime",
                "filterTopic": "string"
            },
            "actions": {
                "matchActionList": [
                    {
                        "type": "string",
                        "relatedProduct": "string",
                        "displayName": "string",
                        "modifyTime": "localDateTime",
                        "registerTime": "localDateTime",
                        "relatedProductAction": "json"
                    }
                ],
                "errorAction": {
                    "type": "string",
                    "relatedProduct": "string",
                    "displayName": "string",
                    "modifyTime": "localDateTime",
                    "registerTime": "localDateTime",
                    "relatedProductAction": "json"
                }
            }
        }
    }
    
    CategoryTypeDescription
    statusstringIndicates whether response was successful
    body.rule.namestringName of the rule
    body.rule.descriptionstringDescription of the rule
    body.rule.statusstringRule status
    body.rule.querystringrule query
    body.rule.modifyTimelocalDateTimeLast modified date
    body.rule.registerTimelocalDateTimerule creation date
    body.rule.filterTopicstringrule topic
    body.actions.matchActionList[].typestringAction role (M: matchedAction, E: errorAction)
    body.actions.matchActionList[].relatedProductstringAction type
    body.actions.matchActionList[].displayNamestringAction primary name
    body.actions.matchActionList[].modifyTimestringAction last modified date
    body.actions.matchActionList[].registerTimestringAction creation date
    body.actions.matchActionList[].relatedProductActionjsonAction details
    body.actions.errorAction.typestringAction role (M: matchedAction, E: errorAction)
    body.actions.errorAction.relatedProductstringError action type
    body.actions.errorAction.displayNamestringError action primary name
    body.actions.errorAction.modifyTimestringError action last modified date
    body.actions.errorAction.registerTimestringError action creation date
    body.actions.errorAction.relatedProductActionjsonError action details

    Response example

    {
        "status": "SUCCESS",
        "body": {
            "rule": {
                "name": "lux",
                "description": "turn off",
                "status": "ENABLE",
                "query": "select lux, bulb_id from \"myhome100/abc/+/abc\" where lux > -1",
                "modifyTime": "2020-09-27 12:52:08",
                "registerTime": "2020-09-27 12:52:08",
                "filterTopic": "myhome100/abc/+/abc"
            },
            "actions": {
                "matchActionList": [
                    {
                        "type": "M",
                        "relatedProduct": "REPUBLISH",
                        "displayName": "republish_a",
                        "modifyTime": "2020-09-27 12:52:08",
                        "registerTime": "2020-09-27 12:52:08",
                        "relatedProductAction": {
                            "topic": "republish_a"
                        }
                    }
                ],
                "errorAction": {
                    "type": "E",
                    "relatedProduct": "REPUBLISH",
                    "displayName": "republish_a",
                    "modifyTime": "2020-09-27 12:52:08",
                    "registerTime": "2020-09-27 12:52:08",
                    "relatedProductAction": {
                        "topic": "republish_a"
                    }
                }
            }
        }
    }
    

    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.