Loyalty Receipts Core API
API Endpoint
api.receipts.wlloyalty.net/v1Introduction
White Label Loyalty Core Receipts API.
Authorization
All requests to the API must contain a X-Api-Key header to identify your
tenant account. In addition to the API key, some methods additionally require
a Authorization header to identify the user or entity accessing the API, and
ensure the requester has sufficient permissions for the requested operation.
This means that there are three levels of authorization which you should be aware when using this API:
-
🔑 Anonymous (API key only)
-
👤 User (API key + end-user auth token)
-
🔐 Admin (API key + administrative auth token)
Each API method described in this documentation will advise which type of authorization is requried.
Receipts ¶
Receipts Collection ¶
Headers
Content-Type: application/json
X-Api-Key: $api_key
Authorization: Bearer $access_tokenBody
{
"useParser": true,
"submitter": {
"authIdentifier": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50"
},
"pictureUrl": "https://example.com/receiptImage.jpg",
"submissionPosition": {
"longitude": 170.9021,
"latitude": 80.9021
},
"metadata": {
"source": "API",
"campaignId": "ExampleCampaign",
"key": "value"
}
}Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"useParser": {
"type": "boolean"
},
"submitter": {
"type": "object",
"properties": {
"authIdentifier": {
"type": "string"
}
},
"required": [
"authIdentifier"
]
},
"pictureUrl": {
"type": "string"
},
"submissionPosition": {
"type": "object",
"properties": {
"longitude": {
"type": "number"
},
"latitude": {
"type": "number"
}
},
"required": [
"longitude",
"latitude"
]
},
"metadata": {
"type": "object",
"properties": {
"source": {
"type": "string"
},
"campaignId": {
"type": "string"
},
"key": {
"type": "string"
}
},
"required": [
"source"
]
}
},
"required": [
"useParser",
"pictureUrl"
]
}Headers
Content-Type: application/json; charset=utf-8Body
{
"status": "success",
"data": {
"id": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"status": "PENDING",
"paramountReview": {
"id": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"verdict": "ABSTAIN",
"reason": "OTHER",
"createdAt": "2017-11-11T06:00:00.000Z",
"isAutomated": true,
"reviwer": {
"authIssuer": "auth.wlloyalty.net",
"authIdentifier": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"name": "Jane Doe"
},
"comment": "Hello, world!"
}
}
}Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"status": {
"type": "string",
"enum": [
"PENDING",
"AUTHORIZED",
"REJECTED"
]
},
"paramountReview": {
"type": [
"object",
"null"
],
"properties": {
"id": {
"type": "string"
},
"verdict": {
"type": "string",
"enum": [
"ABSTAIN",
"REJECT",
"AUTHORIZE"
]
},
"reason": {
"type": "string",
"enum": [
"OTHER",
"VERIFIED",
"VALID_DATA",
"FLAGGED_FOR_SPOT_CHECK",
"DUPLICATE",
"INVALID_MERCHANT",
"INVALID_DATE",
"INSUFFICIENT_DATA",
"SUSPICIOUS",
"SUSPICIOUS_CONTEXT",
"RULE_ENGINE_THREW_ERROR",
"INVALID_VENUE",
"FORMAT_SUBMISSION_LIMIT_EXCEEDED",
"MERCHANT_SUBMISSION_LIMIT_EXCEEDED",
"NO_QUALIFYING_PRODUCTS",
"INVALID_MULTIPAGE_CLAIM",
"TEST"
]
},
"createdAt": {
"type": "string"
},
"isAutomated": {
"type": "boolean"
},
"reviwer": {
"type": [
"object",
"null"
],
"properties": {
"authIssuer": {
"type": "string"
},
"authIdentifier": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"authIssuer",
"authIdentifier"
]
},
"comment": {
"type": [
"string",
"null"
]
}
},
"required": [
"id",
"verdict",
"reason"
]
}
},
"required": [
"id",
"status",
"paramountReview"
]
}
}
}Claim a ReceiptPOST/receipts
This endpoint can be used to submit a claim for a receipt/invoice by a user or on behalf of a user. The endpoint can be operated in two modes Default or Preparsed. The request payload differs between these two modes, use the buttons on the right to show the request example for either mode.
Default Mode
The default mode is intended for use when you want to submit only an image of a receipt and let the API handle both parsing and claim management. For this request the only required data is a URL to the publically accessible image.
This can be called either with the user’s own authentication token or otherwise an admin token can be provided in which case the user who is making the claim must be specified in the submitter property.
Preparsed Mode
The preparsed mode can be used in cases where you have already obtained the parsed receipt data and just want to register it with the claim management system.
Only admin tokens are accepted in this mode so the user who is making the claim must be specified in the submitter property.
Response Codes
Status
-
PENDING- No definite automated decision could be made and so it has been sent for manual review. -
REJECTED- It has been automatically rejected for the reason given inparamountReview.reason. -
AUTHORIZED- It has been automatically authorized and is considered a valid submission.
Reason
-
OTHER -
VERIFIED -
VALID_DATA -
FLAGGED_FOR_SPOT_CHECK -
DUPLICATE -
INVALID_MERCHANT -
INVALID_DATE -
INSUFFICIENT_DATA -
SUSPICIOUS -
SUSPICIOUS_CONTEXT -
RULE_ENGINE_THREW_ERROR -
INVALID_VENUE -
FORMAT_SUBMISSION_LIMIT_EXCEEDED -
MERCHANT_SUBMISSION_LIMIT_EXCEEDED -
NO_QUALIFYING_PRODUCTS -
INVALID_MULTIPAGE_CLAIM -
TEST
🔐 Multiple authorization modes
Requests to this method require either:
👤 User Authorization
🔒 Admin Authorization with admin:receipts scope
Details are explained above. Non-compliant requests will be rejected.
Headers
Content-Type: application/json; charset=utf-8Body
{
"status": "success",
"data": [
{
"id": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"createdAt": "2017-11-11T06:00:00.000Z",
"updatedAt": "2017-11-11T06:00:00.000Z",
"status": "PENDING",
"notionallyServedAt": "2017-11-11T06:00:00.000Z",
"serviceDate": "2017-11-11",
"serviceTime": "06:00:00",
"ocrConfidence": "0.75",
"total": 110.99,
"subtotal": 110.99,
"correctedTotal": 110.99,
"barcode": "012318432"
}
]
}Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "string"
},
"data": {
"type": "array"
}
}
}List ReceiptsGET/receipts{?limit,skip,sort,order,filter}
Get a list of all receipts which have been claimed by users for your tenant.
🔐 Admin authorization required
Requests to this method must provide an Authorization header containing a valid administrative token with admin:receipts scope. Non-compliant requests will be rejected.
Filtering
It is possible to apply basic filter conditions to the result set using the filter query parameter. This parameter accepts an O-Rison encoded JSON object expressing the set of conditions to be applied.
The general format of this filter object (expressed in JSON) is as follows:
{
"field1": { "operator": "value" },
"field2": { "operator": "value" }
}
Where field1 and field2 are field names of this entity, operator is one of [eq, neq, gt, lt, in, has, like], and "value" is the exact value to compare against. The like operator accepts a wild card % which means it will accept any value in place of it e.g %App% will find Web App, the like operator also isn’t case sensitive. The value need not necessarily be a string, the type appropriate for the field should be used. See the O-Rison documentation for help on how to format other types. Dates and datetimes should be passed as ISO 8601 strings.
The same filter encoded as O-Rison would be as follows:
field1:(operator:'value'),field2:(operator:'value')
When using the in operator the value should be an array.
Arrays are expressed by enclosing a comma separated list of elements within !().
For example:
field3:(in:!('value1','value2'))
- limit
number(optional) Example: 10The number of items to retrieve.
- skip
number(optional) Example: 0The number of items to skip before selecting.
- sort
string(optional) Example: createdAtThe property to use for sorting.
Choices:
createdAtupdatedAtnotionallyServedAttotalsubtotal- order
string(optional) Example: ASCThe order to sort items.
Choices:
ASCDESC- filter
string(optional) Example: total:(gt:100)O-Rison encoded filter string
Individual Receipt ¶
Headers
Content-Type: application/json; charset=utf-8Body
{
"status": "success",
"data": {
"id": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"status": "PENDING",
"paramountReview": {
"id": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"verdict": "ABSTAIN",
"reason": "OTHER",
"createdAt": "2017-11-11T06:00:00.000Z",
"isAutomated": false,
"reviwer": {
"authIssuer": "auth.wlloyalty.net",
"authIdentifier": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"name": "Jane Doe"
},
"comment": null
},
"createdAt": "2017-11-11T06:00:00.000Z",
"updatedAt": "2017-11-11T06:00:00.000Z",
"submitter": {
"authIdentifier": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50"
},
"ocrConfidence": "0.75",
"total": 110.99,
"subtotal": 110.99,
"barcode": "012318432",
"transactionId": "012318432",
"lineItems": [
{
"quantity": 2,
"description": "Banana",
"identifier": "SKU123",
"unit": "Bunch",
"unitPrice": 1.99,
"totalPrice": 3.98,
"metadata": {
"key": "value"
},
"productId": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50"
}
],
"pictureUrl": "https://example.com/receiptImage.jpg",
"locationIdentifier": "1235",
"locationAddress": "123 Road Street, Leeds",
"submissionPosition": {
"longitude": 170.9021,
"latitude": 80.9021
},
"formatSlug": "example-format",
"merchantName": "Burger King",
"language": "en",
"timezone": "Europe/London",
"serviceDate": "2017-11-11",
"serviceTime": "06:00:00",
"servedAt": "2017-11-11T06:00:00.000Z",
"metadata": {
"source": "API",
"campaignId": "ExampleCampaign",
"key": "value"
}
}
}Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"status": {
"type": "string",
"enum": [
"PENDING",
"AUTHORIZED",
"REJECTED"
]
},
"paramountReview": {
"type": [
"object",
"null"
],
"properties": {
"id": {
"type": "string"
},
"verdict": {
"type": "string",
"enum": [
"ABSTAIN",
"REJECT",
"AUTHORIZE"
]
},
"reason": {
"type": "string",
"enum": [
"OTHER",
"VERIFIED",
"VALID_DATA",
"FLAGGED_FOR_SPOT_CHECK",
"DUPLICATE",
"INVALID_MERCHANT",
"INVALID_DATE",
"INSUFFICIENT_DATA",
"SUSPICIOUS",
"SUSPICIOUS_CONTEXT",
"RULE_ENGINE_THREW_ERROR",
"INVALID_VENUE",
"FORMAT_SUBMISSION_LIMIT_EXCEEDED",
"MERCHANT_SUBMISSION_LIMIT_EXCEEDED",
"NO_QUALIFYING_PRODUCTS",
"INVALID_MULTIPAGE_CLAIM",
"TEST"
]
},
"createdAt": {
"type": "string"
},
"isAutomated": {
"type": "boolean"
},
"reviwer": {
"type": [
"object",
"null"
],
"properties": {
"authIssuer": {
"type": "string"
},
"authIdentifier": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"authIssuer",
"authIdentifier"
]
},
"comment": {
"type": [
"string",
"null"
]
}
},
"required": [
"id",
"verdict",
"reason"
]
},
"createdAt": {
"type": "string"
},
"updatedAt": {
"type": "string"
},
"submitter": {
"type": "object",
"properties": {
"authIdentifier": {
"type": "string"
}
},
"required": [
"authIdentifier"
]
},
"ocrConfidence": {
"type": "string"
},
"total": {
"type": "number"
},
"subtotal": {
"type": "number"
},
"barcode": {
"type": "string"
},
"transactionId": {
"type": "string"
},
"lineItems": {
"type": "array"
},
"pictureUrl": {
"type": "string"
},
"locationIdentifier": {
"type": "string"
},
"locationAddress": {
"type": "string"
},
"submissionPosition": {
"type": "object",
"properties": {
"longitude": {
"type": "number"
},
"latitude": {
"type": "number"
}
},
"required": [
"longitude",
"latitude"
]
},
"formatSlug": {
"type": "string"
},
"merchantName": {
"type": "string"
},
"language": {
"type": "string"
},
"timezone": {
"type": "string"
},
"serviceDate": {
"type": "string"
},
"serviceTime": {
"type": "string"
},
"servedAt": {
"type": "string"
},
"metadata": {
"type": "object",
"properties": {
"source": {
"type": "string"
},
"campaignId": {
"type": "string"
},
"key": {
"type": "string"
}
},
"required": [
"source"
]
}
},
"required": [
"id",
"status",
"paramountReview",
"createdAt",
"updatedAt",
"submitter",
"ocrConfidence",
"timezone",
"serviceDate",
"serviceTime",
"servedAt"
]
}
}
}Retrieve a ReceiptGET/receipts/{id}
Retrieve the details of a single receipt.
🔐 Admin authorization required
Requests to this method must provide an Authorization header containing a valid administrative token with admin:receipts scope. Non-compliant requests will be rejected.
- id
uuid(required) Example: 99afedd5-75de-4833-88cc-a0caf485e354ID of the Receipt to retrieve
Receipt Reviews ¶
Headers
Content-Type: application/jsonBody
{
"verdict": "ABSTAIN",
"reason": "OTHER"
}Headers
Content-Type: application/json; charset=utf-8Body
{
"status": "success",
"data": {
"id": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"verdict": "ABSTAIN",
"reason": "OTHER"
}
}Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"verdict": {
"type": "string",
"enum": [
"ABSTAIN",
"REJECT",
"AUTHORIZE"
]
},
"reason": {
"type": "string",
"enum": [
"OTHER",
"VERIFIED",
"VALID_DATA",
"FLAGGED_FOR_SPOT_CHECK",
"DUPLICATE",
"INVALID_MERCHANT",
"INVALID_DATE",
"INSUFFICIENT_DATA",
"SUSPICIOUS",
"SUSPICIOUS_CONTEXT",
"RULE_ENGINE_THREW_ERROR",
"INVALID_VENUE",
"FORMAT_SUBMISSION_LIMIT_EXCEEDED",
"MERCHANT_SUBMISSION_LIMIT_EXCEEDED",
"NO_QUALIFYING_PRODUCTS",
"INVALID_MULTIPAGE_CLAIM",
"TEST"
]
}
},
"required": [
"id",
"verdict",
"reason"
]
}
}
}Submit a Receipt ReviewPOST/receipts/{id}/reviews
Submit a new receipt review.
🔐 Admin authorization required
Requests to this method must provide an Authorization header containing a valid administrative token with admin:receipts scope. Non-compliant requests will be rejected.
- id
uuid(required) Example: 99afedd5-75de-4833-88cc-a0caf485e354ID of the Receipt for which to submit a Review
Headers
Content-Type: application/json; charset=utf-8Body
{
"status": "success",
"data": [
{
"id": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"verdict": "ABSTAIN",
"reason": "OTHER",
"createdAt": "2017-11-11T06:00:00.000Z",
"isAutomated": true,
"reviwer": {
"authIssuer": "auth.wlloyalty.net",
"authIdentifier": "8d68cb91-202a-4c62-a867-8f9a8a1e2f50",
"name": "Jane Doe"
},
"comment": "Hello, world!"
}
]
}Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "string"
},
"data": {
"type": "array"
}
}
}List Receipt ReviewsGET/receipts/{id}/reviews
List all Reviews for a given Receipt.
🔐 Admin authorization required
Requests to this method must provide an Authorization header containing a valid administrative token with admin:receipts scope. Non-compliant requests will be rejected.
- id
uuid(required) Example: 99afedd5-75de-4833-88cc-a0caf485e354ID of the Receipt for which to submit a Review
Transactions Rule Engine ¶
Introduction
The White Label Loyalty (WLL) Transactions Rule Engine API enables developers to do advanced post-processing operations after the submission of a Transaction to the WLL platform.
A Transaction can be submitted in the form of a Receipt, an entity from a CSV dump of all orders from a POS system, etc.
Use case:
Each Tenant can have multiple Rule Sets. Each Rule Set consists of a list of Rules, that work together to form a decision tree.
Whenever a Transaction (eg Receipt) is submitted to the WLL system, the Rule Engine is used to do some post-processing checks on the Transaction.
These checks result in JSON data as the final output, which can then be used by the system that invoked the Rule Engine for its own domain specific use-case. (Example, in the Receipt module, the ReceiptReviewer uses the RuleEngine to do some automated checks, uses the result to give an automated Review verdict, and then sends the output as a payload in an Event to the Rewards module.
Basic logic and additional features:
The engine first gets the most appropriate active RuleSet for the incoming Transaction, and then runs all the valid Rules of the set.
-
The core rule engine is a 3rd party library: https://github.com/cachecontrol/json-rules-engine
-
Each Rule has
RulePropertiesfield, which defines the conditions that the Transaction is checked for. -
After the ‘success’ or ‘failure’ of the Rule, the RuleEngine appends the appropriate
ResultParamsdefined for this Rule, into aRuleEngineResponseJSON object. -
Rules can be run parallely or serially, based on the
priorityset. -
Chaining of rules:
Rules can also be chained together by using a key set in a higher order Rule’s
resultParams, as a part of the next Rule’sruleProperties.conditions. -
Custom Rules:
CUSTOMrules are defined directly usingrulePropertieswhich is typed out by the admin manually. This provides a lot of flexibility in the kind of rules that can be added to the systems. -
Pre-defined Rules:
For rules that handle common use-cases, the rule making logic is abstracted away by some pre-defined rules. Eg: BASKET rules are used for product matching checks.
-
Custom Operators:
Additional flexibility for creating more advanced rules is possible, by creating Custom
RuleOperators. Example, thevenueMatchesoperator checks whether a transaction was made in a given venue. -
Special
RuleResultParamskeys:There are two special keys which provide specific functionalities after a Rule is executed:
- `stopRuleEngine` (boolean): After executing a Rule, if the Rule Engine finds that the ResultParams has this key and the value set to true, the Rule Engine first appends the other valid ResultParams of this Rule to the response, and then exits out of execution immediately, without running any other rule of lower priority. NOTE: It may still execute rules of the same priority. - `verdict` (enum): This is a special key, which is used by the ReceiptReviewer to either Reject the receipt or Abstain the receipt. If the rule engine Authorizes or doesn't set the Verdict, the final Review's verdict isn't influenced by the rule engine.
Example of a Custom rule’s RuleProperties:
Refer to https://github.com/cachecontrol/json-rules-engine for more details. For more details regarding parsing the path, refer to https://github.com/s3u/JSONPath
{
conditions: {
all: [
{
any: [
{
fact: "request",
operator: "contains",
value: "9ad8c892-5c08-42c3-a7d8-dcb325d3c1e9",
path: "$.transaction.lineItems[*].productId"
},
{
fact: "request",
operator: "equal", // To handle a single lineitems matching. HACK.
value: "9ad8c892-5c08-42c3-a7d8-dcb325d3c1e9",
path: "$.transaction.lineItems[*].productId"
}
]
},
{
any: [
{
path:
"$.transaction.lineItems[?(@.productId==='9ad8c892-5c08-42c3-a7d8-dcb325d3c1e9')].unitPrice",
fact: "request",
operator: "contains", // To handle an array of lineitems matching.
// NOTE: If any one of the filtered line items matches, the answer is true.
value: 12.2
},
{
path:
"$.transaction.lineItems[?(@.productId==='9ad8c892-5c08-42c3-a7d8-dcb325d3c1e9')].unitPrice",
fact: "request",
operator: "equal", // To handle a single lineitems matching. HACK.
value: 12.2
}
]
}
]
},
event: { type: "prawns-present" },
priority: 10 // IMPORTANT! Set a high priority for this, if you want it to run first
};
Rule Sets ¶
Headers
Content-Type: application/jsonBody
{
"name": "Deeset Rules",
"isActive": true,
"ruleDefinitions": [
{
"type": "CUSTOM",
"name": "prawns-present",
"priority": 10,
"resultParams": {
"success": [
{
"key": "prawnsPresent",
"value": true
}
],
"failure": [
{
"key": "prawnsPresent",
"value": false
}
]
},
"ruleProperties": {
"conditions": {
"all": [
{
"any": [
{
"fact": "request",
"operator": "contains",
"value": "c1417eb1-ff83-4027-a5ae-b5bde2984ef6",
"path": "$.transaction.lineItems[*].productId"
},
{
"fact": "request",
"operator": "equal",
"value": "c1417eb1-ff83-4027-a5ae-b5bde2984ef6",
"path": "$.transaction.lineItems[*].productId"
}
]
},
{
"any": [
{
"path": "$.transaction.lineItems[?(@.productId==='c1417eb1-ff83-4027-a5ae-b5bde2984ef6')].unitPrice",
"fact": "request",
"operator": "contains",
"value": 12.2
},
{
"path": "$.transaction.lineItems[?(@.productId==='c1417eb1-ff83-4027-a5ae-b5bde2984ef6')].unitPrice",
"fact": "request",
"operator": "equal",
"value": 12.2
}
]
}
]
},
"event": {
"type": "prawns-present"
},
"priority": 10
}
}
]
}Headers
Content-Type: application/json; charset=utf-8Body
{
"status": "success",
"data": {
"tenant": {
"name": "Wehner - Rice",
"slug": "sit-cupiditate-et",
"authentication": {
"issuer": "https://wll-restaurant.eu.auth0.com/",
"jwksUrl": "https://wll-restaurant.eu.auth0.com/.well-known/jwks.json",
"algorithm": "RS256"
},
"key": "9QqcmiHBUs3ydSeca70nU2CdOBUCDmdS71OapD4y",
"eventSecrets": {},
"configuration": {},
"id": "4d72ea9c-9830-41f0-9614-64d9b7ca1c33"
},
"name": "Deeset Rules",
"isActive": true,
"createdAt": "2020-02-10T00:18:09.714Z",
"updatedAt": "2020-02-10T00:18:09.714Z",
"id": "c30a7b53-8c01-41a5-85c6-e3f3fe514677",
"rules": [
{
"name": "prawns-present",
"ruleProperties": {
"conditions": {
"all": [
{
"any": [
{
"fact": "request",
"operator": "contains",
"value": "c1417eb1-ff83-4027-a5ae-b5bde2984ef6",
"path": "$.transaction.lineItems[*].productId"
},
{
"fact": "request",
"operator": "equal",
"value": "c1417eb1-ff83-4027-a5ae-b5bde2984ef6",
"path": "$.transaction.lineItems[*].productId"
}
]
},
{
"any": [
{
"path": "$.transaction.lineItems[?(@.productId==='c1417eb1-ff83-4027-a5ae-b5bde2984ef6')].unitPrice",
"fact": "request",
"operator": "contains",
"value": 12.2
},
{
"path": "$.transaction.lineItems[?(@.productId==='c1417eb1-ff83-4027-a5ae-b5bde2984ef6')].unitPrice",
"fact": "request",
"operator": "equal",
"valuse": 12.2
}
]
}
]
},
"event": {
"type": "prawns-present"
},
"priority": 10
},
"resultParams": {
"success": [
{
"key": "prawnsPresent",
"value": true
}
],
"failure": [
{
"key": "prawnsPresent",
"value": false
}
]
},
"configuration": null,
"createdAt": "2020-02-10T00:18:09.714Z",
"priority": 10,
"updatedAt": "2020-02-10T00:18:09.714Z",
"type": "CUSTOM",
"id": "8bb331ce-548c-4896-9675-40afc300f8ba"
}
]
}
}Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"updatedAt": {
"type": "string"
},
"name": {
"type": "string",
"description": "Optional."
},
"isActive": {
"type": "boolean",
"description": "Required."
},
"rules": {
"type": "array",
"description": "Optional. A Rule Set can be created without any Rules defined at first."
}
},
"required": [
"id",
"createdAt",
"updatedAt",
"isActive"
]
}
}
}Create a RuleSetPOST/transactions-rule-engine/rule-sets
Create a new rule set. It takes a JSON object containing info about the RuleSet and a collection of Rules in the form of RuleDefinitions.
RuleSetDefinition contains
-
name: (string) - Optional. Example : ‘January Rules’ -
isActive: true (boolean, required) - Required. -
ruleDefinitions(array[RuleDefinition]) - Optional. A Rule Set can be created without any Rules defined at first.
Each RuleDefinition contains:
-
type:CUSTOM,BASKET(enum, required) - Required. Enum used to specificy if this is a custom rule or a predefined one. -
name(string, required) - Required. In case of rule type =CUSTOM, make sure that this is the same asruleProperties.event.type. -
priority(number, required) - Required. In case of rule type =CUSTOM, make sure that this is the same asruleProperties.priority. Rules with higher priority are run first. Rules with the same priority are run parallely. -
ruleProperties(RuleProperties) - Required only forCUSTOMrule types.Where
RulePropertiesconsists of:-
conditions(object, required) - Required. Defines the criteria that the rule engine evaluates the Transaction against. -
event(Event, required) - Defines the event that is fired when the rule is run. Should be the same asrule.name.Where
Eventconsists of:- type (string, required) -
priority(number) - Should be the same asrule.priority.
-
-
configuration(RuleConfiguration) - Required only for predefined rule types, egBASKETtype. This is used to inflate the ruleProperties, internally. Defines the properties of the rule, depending on thetype.BasketRuleConfiguration(RuleConfiguration). Used forBASKETtype of rules, and is used to check for product related business logic.- `productId` (string, required) - Defines the productId to check for the presence of. - `isUnitPriceCheckNeeded` (boolean, required) - `true` if the rule should also check for a matching price. - `overridingUnitPriceToCheckAgainst` (number) - Used in conjunction with `isUnitPriceCheckNeeded`. If provided, the rule engine tries to match against this price. -
resultParams(RuleResultParams, required) - Required. Used to define the fields that get added to the rule engine response, on eithersuccessorfailureresult of the rule.RuleResultParamsis defined as:-
success(array[KeyValuePair], required) - Defines what key values get returned by the Rule Engine when the rule passes. -
failure(array[KeyValuePair], required) - Defines what key values get returned by the Rule Engine when the rule fails.KeyValuePairis defined as:key(string, required) - Name of the key. Example:isPepsiAvailable.value(required) - Can be ofanytype.
-
Headers
Content-Type: application/json; charset=utf-8Body
{
"status": "success",
"data": [
{
"name": "Deeset Rules",
"isActive": true,
"createdAt": "2020-02-10T02:27:51.084Z",
"updatedAt": "2020-02-10T02:27:51.084Z",
"id": "2375f2e4-20ab-4cba-8b31-8e3a2634734a",
"rules": [
{
"name": "prawns-present",
"ruleProperties": {
"event": {
"type": "prawns-present"
},
"priority": 10,
"conditions": {
"all": [
{
"any": [
{
"fact": "request",
"path": "$.transaction.lineItems[*].productId",
"value": "837eec03-74ff-4758-8cb8-e58ee28c2612",
"operator": "contains"
},
{
"fact": "request",
"path": "$.transaction.lineItems[*].productId",
"value": "837eec03-74ff-4758-8cb8-e58ee28c2612",
"operator": "equal"
}
]
},
{
"any": [
{
"fact": "request",
"path": "$.transaction.lineItems[?(@.productId==='837eec03-74ff-4758-8cb8-e58ee28c2612')].unitPrice",
"value": 12.2,
"operator": "contains"
},
{
"fact": "request",
"path": "$.transaction.lineItems[?(@.productId==='837eec03-74ff-4758-8cb8-e58ee28c2612')].unitPrice",
"value": 12.2,
"operator": "equal"
}
]
}
]
}
},
"resultParams": {
"failure": [
{
"key": "prawnsPresent",
"value": false
},
{
"key": "verdict",
"value": "FAIL"
}
],
"success": [
{
"key": "prawnsPresent",
"value": true
},
{
"key": "verdict",
"value": "SUCCESS"
}
]
},
"configuration": null,
"createdAt": "2020-02-10T02:27:58.072Z",
"priority": 10,
"updatedAt": "2020-02-10T02:27:58.072Z",
"type": "CUSTOM",
"id": "211d230e-66bf-49a1-90ea-8cb70ab5232c"
},
{
"name": "pepsi-present",
"ruleProperties": {
"event": {
"type": "pepsi-present"
},
"priority": 9,
"conditions": {
"all": [
{
"any": [
{
"fact": "request",
"path": "$.transaction.lineItems[*].productId",
"value": "c94074f6-42e2-413a-a803-edff365b1b62",
"operator": "contains"
},
{
"fact": "request",
"path": "$.transaction.lineItems[*].productId",
"value": "c94074f6-42e2-413a-a803-edff365b1b62",
"operator": "equal"
}
]
},
{
"any": [
{
"fact": "request",
"path": "$.transaction.lineItems[?(@.productId==='c94074f6-42e2-413a-a803-edff365b1b62')].unitPrice",
"value": 10.2,
"operator": "contains"