Skip to content

Discount codes

A DiscountCode is a code your shoppers enter. ObjectsGrid works out what it takes off every time a Cart is read, checks it again at checkout, and counts the use in the same step as the Order is created: two shoppers can't both spend a code's last use.

A code

Its id is the code. It is stored in upper case; shoppers may type it in any case.

curl -X POST https://apis.objectsgrid.com/discountcodes -H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' -d '{
    "id": "SUMMER25", "name": [{"at_language": "en", "at_value": "Summer sale"}],
    "percentOff": 25, "validThrough": "2027-08-31T23:59:59Z",
    "minimumOrderValue": {"value": 50, "currency": "EUR"}, "maxUses": 1000, "maxUsesPerCustomer": 1}'
  • What it gives: percentOff, or amountOff with priceCurrency, off the eligible lines; or freeShipping, which your app applies. One of the three.
  • When it applies: from validFrom to validThrough, when the eligible lines total at least minimumOrderValue.
  • To what: the Offers in eligibleOffers, or the Offers of products with one of the eligibleCategories; every line when it names neither.
  • To whom: customers whose Person has one of the eligibleCustomerTags, such as tier = gold.
  • How often: maxUses in all, maxUsesPerCustomer per customer (the cart then needs a customer). usesCount shows the checkouts that used it; ObjectsGrid sets it.

A code's id is used once in an Organization Account, even after it is deleted. Codes are private: the default policy never lets anonymous callers list or read them, so they can't be guessed by listing.

On the cart

The shopper's cart holds the code in discountCode. A read of the cart shows what it takes off:

{"discountCode": "summer25",
 "discount": [{"at_type": "MonetaryAmount", "currency": "EUR", "value": 20}],
 "totalPrice": [{"at_type": "MonetaryAmount", "currency": "EUR", "value": 60}]}

When the code doesn't apply, discountRefused says why ("the code expired on ...", "the code is used up", "the eligible lines total less than the code's minimum, 50 EUR") and the total is the full price.

At checkout

POST /carts/<id>/checkout works the discount out again. If the code no longer applies (it ran out between the shopper's last look and the checkout), the checkout is refused with 409 DISCOUNT_CODE_NOT_APPLICABLE, and nothing is ordered: remove the code or change the cart, and check out again. Otherwise the use is counted, and the Order records discountCode, discount and discountCurrency.

A discountCode that no DiscountCode has is passed to the Order as it is, unapplied, as before DiscountCodes existed: an app that runs its own codes keeps working.