API Intro
In this guide we're going to walk through setting up a discount that gives 10% off a users basket when they spend 30 GBP using the Builder API. The Processor API section gives an example of how to call the Processor API to evaluate the discount.
This guide uses the API only, if you'd prefer to read a guide on how to do this using the tooling see Creating your first discount.
Firstly you need to create a project in the portal. If you haven't done this yet see Account Setup for details of how to do this.
Builder API
To create a discount that gives 10% off a users basket when they spend 30 GBP, make the following request:
curl -X 'POST' \
'https://discounts-management.dovetech.com/discounts' \
-H 'accept: application/json' \
-H 'x-api-key: [Builder API Key]' \
-H 'Content-Type: application/json' \
-d '{
"name": "Minimum Spend Discount",
"conditions": [
{
"lineItemGroupCondition": {
"type": "MinimumSpend",
"values": [
{
"currencyCode": "GBP",
"value": 30
}
]
}
}
],
"actions": [
{
"type": "AmountOffBasket",
"amountOffType": "PercentOff",
"values": [
{
"value": 10
}
]
}
]
}
'
This discount will then be available on the staging data instance. See Publishing Model for more details.
For more details on the different discount options available in the Builder API see the Builder API - Discount Types guide for more details.
Processor API
An example evaluation request/response is below:
Request
curl -X 'POST' \
'https://discounts.dovetech.com/evaluate' \
-H 'accept: application/json' \
-H 'x-api-key: [Processor API Key]' \
-H 'Content-Type: application/json' \
-d '{
"basket": {
"items": [
{
"quantity": 2,
"price": 58.99
}
]
},
"context": {
"currencyCode": "GBP"
},
"settings": {
"dataInstance": "Staging"
}
}'
Response
{
"actions": [
{
"id": "933b4214-5e0f-4543-a0f1-6c2cd170d348",
"discountId": "284d21a9-a3b3-4cf7-973c-099db0e801c6",
"type": "AmountOffBasket",
"qualifiedCouponCode": null,
"amountOffType": "PercentOff",
"value": 10,
"amountOff": 11.8,
"displayMessages": []
}
],
"basket": {
"total": 106.18,
"totalAmountOff": 11.8,
"items": [
{
"total": 106.18,
"totalAmountOff": 11.8,
"actions": [
{
"id": "933b4214-5e0f-4543-a0f1-6c2cd170d348",
"subItemId": 1,
"amountOff": 5.9
},
{
"id": "933b4214-5e0f-4543-a0f1-6c2cd170d348",
"subItemId": 2,
"amountOff": 5.9
}
]
}
]
},
"aggregates": {
"total": 106.18,
"totalAmountOff": 11.8
},
"costs": [],
"commitId": null,
"evaluationLog": null
}
Note. Line items are returned in the same order they are passed in.
To make the discount available on the live data instance, you need to publish the changes to live. You can do this using the Discount Status endpoint (the discount ID should match the discount you created above):
curl -X 'PUT' \
'https://discounts-management.dovetech.com/discounts/42dda78f-c39d-45e5-b5c0-5d88a86b2fe0/status' \
-H 'accept: application/json' \
-H 'x-api-key: [Builder API Key]' \
-H 'Content-Type: application/json' \
-d '{
"status": "Live"
}'
Next Steps
Review the guides in the Overview section to gain understanding of how the system works.
Basic discounts can be created without any further configuration. To setup more complex use cases you will want to configure all required currencies (see Currencies page for more details), and define the properties that you want to use for evaluation (see Properties)
The Builder section provides further details on how to interact with the Builder APIs.
Review the API documentation: