Skip to main content
POST
Create a discount code

Authorizations

X-Suby-Api-Key
string
header
required

Secret API key. sk_live_… (production) or sk_sandbox_… (sandbox).

Headers

Idempotency-Key
string

Optional key (≤255 chars, e.g. a UUID v4) that makes this POST safe to retry: the first request executes and its response is cached for 24h; a retry with the SAME key replays that response instead of re-executing (no duplicate payment/subscription). A reused key with a different request → 422 IDEMPOTENCY_KEY_CONFLICT; a retry while the first is still in flight → 409. See the Idempotency guide.

Maximum string length: 255
Example:

"5f3b9c2e-1a4d-4f2b-9c31-7e2a1b6d8c04"

Body

application/json

Only the field matching discountType is stored; the other is cleared, so a code can never carry two contradictory discounts.

name
string
required

The code you hand out. Unique per account and environment.

Required string length: 2 - 40
Pattern: ^[A-Z0-9][A-Z0-9_-]*$
Example:

"NOEL2026"

discountType
enum<string>
default:PERCENTAGE
Available options:
PERCENTAGE,
FIXED
discountPercent
integer

Required when discountType=PERCENTAGE.

Required range: 1 <= x <= 99
discountAmountCents
string

Required when discountType=FIXED. Minor units as a string of digits.

Pattern: ^[1-9]\\d*$
Example:

"500"

currency
string

Required when discountType=FIXED.

Pattern: ^[A-Z]{3}$
productIds
string[]

Eligible products. Leave empty to apply to every product.

maxUses
integer | null

Global redemption cap. Null = unlimited. Counts settled redemptions plus checkouts still in flight, so the last use cannot be handed to two buyers at once; an abandoned attempt releases its slot on its own expiry.

Required range: x >= 1
expiresAt
string<date-time> | null
preApply
boolean
default:false

Apply this code on the hosted checkout with no payer input, on every order it covers. A code carried by the session (discountCode on POST /v3/checkout/sessions) wins over it. The payer sees the discount already deducted and can still remove it. A pre-applied code that no longer redeems is silently not applied · the page shows the full price rather than an error the payer did not cause.

Response

Code created

success
boolean
required
Example:

true

data
object
required

Endpoint-specific payload.

message
string