Create a Batch Rule
With this method, you create a new batch rule object.
As with all rule service methods in SAP IoT, you have to provide the ID of the rule project to which the new rule shall be assigned. This ensures that the new rule can access all elements of the data vocabulary defined in the rule project.
Request
URI: /v1/projects/<projectId>/batch-rules
HTTP Method: POST
Permissions: <rule>.c
Request Parameters
| Parameter | Required | Data Type | Description | Parameter Type |
|---|---|---|---|---|
| projectId | Yes | string | Unique ID of the rule project to which the new rule shall be assigned. | Path |
Request Example
/v1/projects/185d9a72-a629-4b94-b421-a2f0301bb072/batch-rulesWith this service request, a new batch rule is created and assigned to the rule project specified by its ID. The detailed settings for the new rule are all contained in the following request payload.
Payload
{
"name": "MyBatchRuleName",
"timeFrame": "PT1H",
"scheduling": {
"startTime": "2019-03-18T13:26:58.756",
"endTime": "2019-03-20T13:26:58.756",
"value": "*/5 * * * * *"
},
"toggle": false,
"texts": [
{
"language": "en",
"shortText": "Short text for my rule",
"description": "Long description for my rule"
},
{
"language": "de",
"shortText": "Kurztext für die Regel",
"description": "Lange Beschreibung für die erstellte Regel"
}
],
"tags": [
{
"tag": "MyRule"
}
],
"inputDataObjectNames": [
{
"name": "timeSeriesDOName_aggregate"
}
],
"brRuleData": {
"Branches": [
{
"Id": "f44194e3a0714e1cb90f6bb7ae194f18",
"SequenceNumber": 1,
"Condition": {
"Expression": "",
"AST": [
{
"Id": "2e0319e60e9b497d80a85e34f06cc047",
"Root": false,
"Value": "100",
"Parentheses": false,
"Children": [],
"Output": {
"DataObjectType": "E",
"BusinessDataType": "N"
}
},
{
"Id": "969dafe70373439fbb93022a011577e4",
"Root": true,
"Value": null,
"Function": "IsGreater",
"Parentheses": false,
"Children": [
{
"Id": "663da75ee4484d7d99e76589683283d4",
"SequenceNumber": 1
},
{
"Id": "2e0319e60e9b497d80a85e34f06cc047",
"SequenceNumber": 2
}
],
"Output": {
"DataObjectType": null,
"BusinessDataType": null
}
},
{
"Id": "663da75ee4484d7d99e76589683283d4",
"Root": false,
"Value": null,
"Reference": "/77d422e394f74dd5a4134a94cbae6b52/caa36402ea414ab98faa831b2ea47508",
"Parentheses": false,
"Children": [],
"Output": null
}
]
},
"Operation": [
{
"Id": "b044d0873e5b4568888a6de2970ecbce",
"SequenceNumber": 3,
"Segment": "77c813a220384e52abcb7cb2a28cc06f",
"Expression": null,
"AST": [
{
"Id": "EEE4B2AF97474F349D31E4A6A611ECB2",
"Root": true,
"Value": "high",
"Parentheses": false,
"Children": [],
"Output": {
"DataObjectType": "E",
"BusinessDataType": "S"
}
}
]
},
{
"Id": "7770379f26274734a1618360bafceb43",
"SequenceNumber": 2,
"Segment": "85a70a28841044bba3d75091f168b4ed",
"Expression": null,
"AST": [
{
"Id": "375FD781637C4E10A2790D065568EEA7",
"Root": true,
"Value": "NewEvent",
"Parentheses": false,
"Children": [],
"Output": {
"DataObjectType": "E",
"BusinessDataType": "S"
}
}
]
}
]
}
],
"Default": {
"Id": "544f71f2d399455fa1d1a9d84949cc0f",
"Operation": [
{
"Id": "0b717244129c4970818c7abd211d1f74",
"SequenceNumber": 4,
"Segment": "39c694c2044047f496459abb16a6a0ce",
"Expression": null,
"AST": [
{
"Id": "94B18535FF2748DD984048C5426F84A4",
"Root": true,
"Value": "",
"Parentheses": false,
"Children": [],
"Output": {
"DataObjectType": "E",
"BusinessDataType": "S"
}
}
]
}
]
}
}
}
| Name | Mandatory | Description |
|---|---|---|
| <name> | yes | Technical name of the rule. |
| <timeFrame> | yes | Specifies a period of time, for which recorded sensor data are aggregated. Values must be formatted according to ISO 8601 (for example, "PT10H"). |
| <startTime> | yes | Start time of rule execution. |
| <endTime> | yes | End time of rule execution. |
| <value> | yes | Cron-formatted string indicating the iteration pattern for rule execution (for example: "*/5 * * * * *" = every 5 minutes). |
| <toggle> | no | Controls how the rule behaves if the rule condition is fulfilled over a longer period:
|
| <inputDataObjectNames> | no | Array of technical names of data objects used as rule input. |
Response
Response Headers
| Header | Description |
|---|---|
| Location |
Path to the newly created rule, for example: /v1/projects/3c814fbf-1a6f-4063-8e25-38ae144dc43c/batch-rules/d1c005f8-7b61-4263-8eb5-76bbc14d57be |
| Etag | Identifier of the rule instance version, for example: 2dadd04e709323c68ac3d65065208e05 |
Response Status and Error Codes
| Code | Description |
|---|---|
| 200 | Rule created successfully. |
| 400 | Bad request. For example, the payload may have caused a validation error. |
| 401 | Unauthorized. Rule couldn't be created due to insufficient access rights. |
| 403 | Forbidden. |
| 404 | Not found. For example, an invalid project ID has been provided. |
Response Example
{
"name": "MyBatchRuleName",
"texts": [
{
"language": "en",
"shortText": "Short text for my rule",
"description": "Long description for my rule"
},
{
"language": "de",
"shortText": "Kurztext für die Regel",
"description": "Lange Beschreibung für die erstellte Regel"
}
],
"tags": [
{
"tag": "MyRule"
}
],
"inputDataObjectNames": [
{
"name": "timeSeriesDOName_aggregate"
}
],
"draftDetails": {
"timeFrame": "PT1H",
"scheduling": {
"startTime": "2019-03-18T13:26:58.756",
"endTime": "2019-03-20T13:26:58.756",
"value": "*/5 * * * * *"
},
"toggle": false,
"brRuleData": {
"Branches": [
{
"Id": "f44194e3a0714e1cb90f6bb7ae194f18",
"SequenceNumber": 1,
"Condition": {
"Expression": "",
"AST": [
{
"Id": "2e0319e60e9b497d80a85e34f06cc047",
"Root": false,
"Value": "100",
"Parentheses": false,
"Children": [],
"Output": {
"DataObjectType": "E",
"BusinessDataType": "N"
}
},
{
"Id": "969dafe70373439fbb93022a011577e4",
"Root": true,
"Value": null,
"Function": "IsGreater",
"Parentheses": false,
"Children": [
{
"Id": "663da75ee4484d7d99e76589683283d4",
"SequenceNumber": 1
},
{
"Id": "2e0319e60e9b497d80a85e34f06cc047",
"SequenceNumber": 2
}
],
"Output": {
"DataObjectType": null,
"BusinessDataType": null
}
},
{
"Id": "663da75ee4484d7d99e76589683283d4",
"Root": false,
"Value": null,
"Reference": "/77d422e394f74dd5a4134a94cbae6b52/caa36402ea414ab98faa831b2ea47508",
"Parentheses": false,
"Children": [],
"Output": null
}
]
},
"Operation": [
{
"Id": "b044d0873e5b4568888a6de2970ecbce",
"SequenceNumber": 3,
"Segment": "77c813a220384e52abcb7cb2a28cc06f",
"Expression": null,
"AST": [
{
"Id": "EEE4B2AF97474F349D31E4A6A611ECB2",
"Root": true,
"Value": "high",
"Parentheses": false,
"Children": [],
"Output": {
"DataObjectType": "E",
"BusinessDataType": "S"
}
}
]
},
{
"Id": "7770379f26274734a1618360bafceb43",
"SequenceNumber": 2,
"Segment": "85a70a28841044bba3d75091f168b4ed",
"Expression": null,
"AST": [
{
"Id": "375FD781637C4E10A2790D065568EEA7",
"Root": true,
"Value": "NewEvent",
"Parentheses": false,
"Children": [],
"Output": {
"DataObjectType": "E",
"BusinessDataType": "S"
}
}
]
}
]
}
],
"Default": {
"Id": "544f71f2d399455fa1d1a9d84949cc0f",
"Operation": [
{
"Id": "0b717244129c4970818c7abd211d1f74",
"SequenceNumber": 4,
"Segment": "39c694c2044047f496459abb16a6a0ce",
"Expression": null,
"AST": [
{
"Id": "94B18535FF2748DD984048C5426F84A4",
"Root": true,
"Value": "",
"Parentheses": false,
"Children": [],
"Output": {
"DataObjectType": "E",
"BusinessDataType": "S"
}
}
]
}
]
}
}
},
"activeDetails": {}
}
The following table provides explanations for those fields that are only present in the response payload, but not in the creation request. The returned field values are automatically determined by the system.
| Name | Description |
|---|---|
| <id> | Unique ID of the newly created rule. The ID is a 36 characters hex code, grouped into sections by hyphens. |
| <projectId> | Unique ID of the rule project to which the rule belongs. |
| <activationDetails.status> |
Activation status of the rule. Possible values:
|
| <outputDataObjectName> | Technical name of the predefined output data object for batch rules. The value is always set to Result_batch. |
| <createdOn> | ISO timestamp of creation time. Example: 2020-12-02T10:43:56.467Z |
| <lastChangedOn> | ISO timestamp of last change. Example: 2020-12-05T10:43:56.467Z |
| <draftDetails> | A field array containing all the settings for the rule in draft version (= inactive). These settings take effect once the rule has been successfully activated. |
| <activeDetails> | A field array containing all the settings for the rule in active version. These settings are currently in effect when the rule is executed. |