Rule.create

Description

Creates a new rule. A rule commands a device or app to perform a particular action when a given event is generated by another device or app. Source device or app and target device or app must be provided. Args for the action may be provided. The example below is the implementation using the REST API of the refuel rule example in the payload documentation.

Request specification

  • Method: POST
  • URL: /rules

Example Request

  • Request URL: https://www.lhings.com/laas/api/v1/rules
  • Request headers: X-Api-Key: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  • Request method: POST
  • Request body:
    {
        "name": "rule1",
        "sourceDevice": "11111111-2222-3333-4444-555555555555",
        "targetDevice": "66666666-7777-8888-9999-000000000000",
        "sourceApp": null,
        "targetApp": null,
        "sourceEvent": "event1",
        "targetAction": "action1",
        "targetActionArgs": [{
            "name": "arg1",
            "value": "123"
        }, {
            "name": "arg2",
            "value": "monday"
        }]
    }

Example Response

  • HTTP status: 201 Created
  • Response body:
    {
        "ruleId": 234
    }

Error summary

  • 201: success.
  • 400: bad request, usually caused by a wrong formatted JSON request body.
  • 401: Api key not provided or invalid.
  • 404: any of the device or apps involved in the rule are not installed.

Refuel rule example

The example below is the implementation using the REST API of the refuel rule example in the payload documentation. Note how connectors are provided as values for the arguments of the action.

{
    "name": "refuel_rule",
    "sourceDevice": "11111111-2222-3333-4444-555555555555",
    "targetDevice": "66666666-7777-8888-9999-000000000000",
    "sourceApp": null,
    "targetApp": null,
    "sourceEvent": "fuel_low",
    "targetAction": "refuel",
    "targetActionArgs": [{
        "name": "position",
        "value": "{{gps_position}}"
    }, {
        "name": "amount_of_fuel",
        "value": "({{distance_for_refuelling}} - {{remaining_distance}}) * 0.1"
    }, {
        "name": "price",
        "value": 20.0
    }]
}
Back to top