Check and validation
How to use the public endpoint to check and validate a rule against a specific payload
Last updated
How to use the public endpoint to check and validate a rule against a specific payload
Last updated
If you need to check and validate a rule against a specific payload, you can leverage the public endpoint:
Where {{your_domain}}
is the unique subdomain of a Commerce Layer organization for which the Rules Engine is enabled.
To do that you just need to send a POST
request using a or access token and passing the rules you want to check along with the payloads you want the rules to be checked against:
payload
An array of objects containing the resource payload(s) you want the rules
to be checked against.
rules
An array of objects containing the rules you want to check against the payload
.
You'll get in the response all the rules outcomes information, including:
The overall matching result of the rules.
The list of all the conditions matchers.
The list of single resources on which the related actions will be applied.
Any errors.
... and more.
The following request checks the outcomes of a rule that should apply a 3% discount to the total amount of the orders paid by credit card against two different order payloads:
The following request checks the outcomes of a couple of rules that should apply a 3% discount to the total amount of the orders paid by credit card and a 1000 cents fixed amount discount to the total amount of the orders that have more than two SKUs, but the rule payloads contain some errors:
The format of the percentage discount value in the first rule is incorrect.
The type of action in the second rule is fixed
(which doesn't exist among the available action types) instead of fixed_amount
.
If you just need to validate the syntax of one or more rules, you can pass an empty object in the payload array "payload": [ { } ]
. If you get a 200 OK
response code, it means that the rule is syntactically correct. Otherwise, the errors will be listed in the response with a 400 Bad request
status code.
The first rule's field is payment_source
(a wrong attribute that doesn't exist in the Core API's resource object) instead of payment_source_type
.