Skip to main content
Scopes: read_discounts to read, write_discounts to change (it includes read_discounts).

The coupon

A coupon always comes with its 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, so SUMMER15 is saved as summer15. Up to 64 characters: letters of any language, digits, - and _. It is unique among the store’s coupons, letter case aside: a taken code answers 409 code_taken.
  • automatic: applied without a code. It has no code ("") and needs a title, 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_products or specific_categories, with at least one buy item (is_buy_item: true) and one get item;
  • needs buy_quantity above 0 when buy_requirement_type is quantity (the default), or buy_amount above 0 when it is amount;
  • needs get_quantity above 0;
  • gives the get items free (get_value_type: "free", the default), or off by get_value, above 0, as a percentage (up to 100) or a fixed amount.
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 422 on its item_id, with its type as the rule (product, variant or category).
  • 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 code coupon has a code; an automatic one has a title and no code;
  • the value rules of its discount type;
  • specific_products and specific_categories have applicable items;
  • starts_at is not after expires_at.
A broken rule answers 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 coupon automatic, send "code": "" and a title with it.
  • Clearing a date takes an explicit null: "expires_at": null removes the expiry, "starts_at": null the start. Leaving the field out keeps it. Every other field refuses null.
  • applicable_items replaces 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 an Idempotency-Key to retry safely. Lists are paginated.