Skip to content

Promotions

Promo codes and automatic discounts are made in Sabiwave, under Online Store › Promotions (from the Premium plan). They apply to orders placed through the API. The API checks them; it doesn’t make or change them.

POST/promotions/validate

Scope promotions:readSecret or publishable key

What code and your automatic discounts take off these items, priced from your catalogue exactly as the order will be. Nothing is reserved: the order uses the code when it’s made, so check as often as the basket changes.

Field Meaning
code The code the shopper typed, in any case. Leave it out to see only your automatic discounts.
items Required. 1 to 100 lines, each { productId, variantId?, quantity }.
customerId Secret key only: also check this customer’s own limits.
Terminal window
curl -X POST "https://api.sabiwave.com/api/v1/public/promotions/validate" \
-H "X-Sabiwave-Public-Key: $SABIWAVE_PUBLISHABLE_KEY" \
-H "Origin: https://shop.example.com" \
-H "Content-Type: application/json" \
-d '{
"code": "WEEKEND10",
"items": [
{
"productId": "01a2160c-6b00-7627-af42-d534badeaea4",
"quantity": 2
}
]
}'
200 OK
{
"success": true,
"data": {
"valid": true,
"code": {
"code": "WEEKEND10",
"description": null,
"discountType": "percentage",
"value": 10
},
"reason": null,
"message": null,
"discountAmount": 4000,
"automatic": [],
"totalDiscount": 4000,
"subtotal": 40000,
"customerChecked": false
}
}
Field Meaning
valid true if the code can be used, false if not, null if you sent no code.
code The code: { code, description, discountType, value }, where value is a percentage for percentage codes and an amount for fixed_amount ones. null if there’s no such code.
reason Why the code can’t be used, as a stable code (below), or null.
message The same, in words you can show the shopper, or null.
discountAmount What the code takes off.
automatic Your automatic discounts that apply: each { kind, name, amount }.
totalDiscount Everything taken off: the code and the automatic discounts.
subtotal The items’ total before these discounts.
customerChecked true when the customer’s own limits were checked (customerId with a secret key).

A code that can’t be used is still a 200: read valid and reason.

200 OK
{
"success": true,
"data": {
"valid": false,
"code": null,
"reason": "PROMO_NOT_FOUND",
"message": "That code isn’t valid.",
"discountAmount": 0,
"automatic": [],
"totalDiscount": 0,
"subtotal": 40000,
"customerChecked": false
}
}
Reason The shopper sees
PROMO_NOT_FOUND That code isn’t valid.
PROMO_INACTIVE That code isn’t active.
PROMO_NOT_STARTED That code isn’t active yet.
PROMO_EXPIRED That code has expired.
PROMO_WRONG_CHANNEL That code can’t be used here.
PROMO_EXHAUSTED That code has been fully used.
PROMO_MIN_SPEND Spend at least (the amount) to use that code.
PROMO_NOT_APPLICABLE That code doesn’t cover anything in this order.
PROMO_NOT_STACKABLE A better offer is already applied.
PROMO_ALREADY_USED You have already used that code.
PROMO_FIRST_ORDER_ONLY That code is for a first order.

A minimum spend is measured against the items, never the delivery fee. A code that doesn’t stack with other offers replaces your automatic discounts when it takes off more than they do together, and is refused with PROMO_NOT_STACKABLE when they’re worth as much or more.

A code can be limited per customer, or to a customer’s first order. For a guest, those rules can’t be checked yet, so the answer leaves them out. They’re always checked when the order is made, and a code that breaks one fails the order with PROMO_ALREADY_USED or PROMO_FIRST_ORDER_ONLY. If your server knows the customer, send their customerId with the secret key to check now:

Terminal window
curl -X POST "https://api.sabiwave.com/api/v1/public/promotions/validate" \
-H "Authorization: Bearer $SABIWAVE_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "WEEKEND10",
"items": [
{
"productId": "01a2160c-6b00-7627-af42-d534badeaea4",
"quantity": 2
}
],
"customerId": "01a22953-aada-745d-a986-131fbe5367bd"
}'
200 OK
{
"success": true,
"data": {
"valid": true,
"code": {
"code": "WEEKEND10",
"description": null,
"discountType": "percentage",
"value": 10
},
"reason": null,
"message": null,
"discountAmount": 4000,
"automatic": [],
"totalDiscount": 4000,
"subtotal": 40000,
"customerChecked": true
}
}