anyshop docs homeStatusOpen the dashboard

API reference Coupons Create a coupon

API referenceCoupons

Create a coupon

POST methodhttps://api.anyshop.io/v1/coupons

A code buyers type at checkout, with the dashboard's rules: a percent or an amount off, every product or the ones you name, a usage limit, one use per buyer email, a start and an end. It works at once unless starts_at is later.

  • Scope coupons:write
  • Live keys only
  • Idempotent with Idempotency-Key
  • 403 store_suspended while suspended

Body

application/json1 required, 8 optional
  • codestring requiredWhat buyers type: 3 to 32 letters and digits, kept in capitalsUp to 64 characters
  • percent_offnumber Percent off each product it applies to: 0.01 to 100, at most two decimals. Send this or amount_off0.01 to 100
  • amount_offinteger Off the order once, in minor units of the store currency: 500 is $5.00. Send this or percent_offAt least 1
  • currencystring Optional check: the store's currency, ISO 4217. Another currency is refused, since amounts off are in the store's3 characters
  • productsarray of strings Product IDs: it applies to these only, up to 200. Left out, every product1 to 200 items
  • usage_limitinteger Uses allowed, counted in each mode on its own1 to 10,000,000
  • once_per_emailboolean One use per buyer email
  • starts_atstring When it starts working, ISO 8601
  • ends_atstring When it stops working, ISO 8601: after starts_at, and not in the past

Headers

  • Idempotency-Keystring Up to 255 characters. A retry with the same key and request gets the first answer, without running twice (24 hours).

Returns

The coupon object.

Errors

Status and error.type
  • 400invalid_requestThe request is not valid; error.param names the field
  • 401authenticationNo API key, or it is not valid
  • 403permissionThe key does not have the scope this needs, or the store is suspended (store_suspended)
  • 404not_foundNot found in the key's store and mode
  • 409conflictConflicts with the object's state (type conflict), or an Idempotency-Key reused for another request (type idempotency, code idempotency_key_reused)
  • 429rate_limitedToo many requests; see Retry-After