read_discounts to read, write_discounts to change (it includes read_discounts).
The coupon
applicable_items. usage_count is how many orders used it: read only, and sending it answers 400. The store’s coupon settings, such as whether the storefront shows the coupon box, are not part of this API.
Code or automatic
code: the shopper types the code at checkout. The code is trimmed and saved lowercased, soSUMMER15is saved assummer15. Up to 64 characters: letters of any language, digits,-and_. It is unique among the store’s coupons, letter case aside: a taken code answers409 code_taken.automatic: applied without a code. It has no code ("") and needs atitle, which the storefront shows.
title is one line of plain text, up to 255 characters, with no <.
Discount types
A
buy_x_get_y coupon:
- applies to
specific_productsorspecific_categories, with at least one buy item (is_buy_item: true) and one get item; - needs
buy_quantityabove 0 whenbuy_requirement_typeisquantity(the default), orbuy_amountabove 0 when it isamount; - needs
get_quantityabove 0; - gives the get items free (
get_value_type: "free", the default), or off byget_value, above 0, as apercentage(up to 100) or afixedamount.
combines_with_product, combines_with_order and combines_with_shipping say which kinds of coupon it can be used with: product coupons (amount_off_products, buy_x_get_y), order coupons (amount_off_order) and shipping coupons (free_shipping). Two coupons combine only when each allows the other’s kind.
What it applies to
applies_to is all (the default), specific_products or specific_categories. The last two need applicable_items, each one:
- At most 100 items, none twice.
- Each must be a live product, variant or category of this store. One that is not answers
422on itsitem_id, with its type as the rule (product,variantorcategory). - Items read back in one order: buy items first, then by type and ID.
Rules
Each field is checked on its own: amounts from 0 to 100,000,000 with at most 4 decimals, counts (min_quantity, buy_quantity, get_quantity, max_uses_per_order) from 0 to 1,000,000, usage_limit from 0 to 1,000,000,000 (0 is no limit), and dates from 2000 to 2100. Then the whole coupon must hold together:
- a
codecoupon has a code; anautomaticone has atitleand no code; - the value rules of its discount type;
specific_productsandspecific_categorieshave applicable items;starts_atis not afterexpires_at.
422 validation_failed, naming every field. See Errors.
On create, only method and discount_type are required. The rest take their defaults: active, a fixed value, applies to all, a quantity buy requirement, free get items, and zero, false or no date for everything else.
Updating
Update a coupon changes only the fields you send, and checks the rules on the coupon it leaves: the saved one with your changes. So a change that would break the coupon is refused even when each field is fine on its own. To turn a code couponautomatic, send "code": "" and a title with it.
- Clearing a date takes an explicit
null:"expires_at": nullremoves the expiry,"starts_at": nullthe start. Leaving the field out keeps it. Every other field refusesnull. applicable_itemsreplaces all the items when you send it;[]removes them.
Deleting
Delete a coupon works as in the dashboard: the coupon stops applying and disappears from lists and reads (404), while orders that used it keep their discount. Its code becomes free for a new coupon.
Changes show at once
The storefront does not cache coupons, so a change takes effect at once. Coupon changes send no events. Create with anIdempotency-Key to retry safely. Lists are paginated.