Add an eligibility or buy-get rule to a discount
Authorizations
A secret API key. Publishable keys cannot reach this API. A key may carry an expiry, and an expired key is refused exactly like an unknown one, with a 401 that names no reason; check the key's expires_at in the dashboard rather than inferring it from a response. When a merchant rolls a key's secret they choose a grace window of up to 3 days, and for its duration BOTH the new secret and the one it replaced authenticate, so an integration moves over on its own deploy schedule instead of at the instant the button is pressed. Move before the window closes: after it, the old secret is refused. Nothing else about this contract moves with a roll. The key keeps its id and its scopes, so the only thing an integration updates is the credential itself.
Headers
A unique key per logical write. Replaying a request with the same key returns the first response byte for byte instead of applying the write twice.
Path Parameters
Body
THIS IS THE GATE. A discount with no eligibility rule applies to EVERY cart, because checkout treats an empty rule set as satisfied, so a discount created without one is unconditional however it was described. Rules AND together. The attribute and operator are checked against what the checkout evaluator can actually compute and an unevaluable pair is refused rather than stored, because a rule the evaluator cannot satisfy is false for every cart and the discount then applies to nothing, silently. The rule is live the moment it is written: a rule only ever NARROWS a discount, so there is no staged state to enable. A retry outside the idempotency window writes a SECOND rule, which narrows further rather than widening.
Required on create. The cart fact this rule tests, from the closed set the checkout evaluator understands. subtotal is MINOR UNITS of the cart's own currency and carries no currency label, so "5000" is 50.00 in a two-decimal currency and "50" is fifty cents. buy and target rules are matched one cart line at a time and can only use items.product.id and items.product.collection_id.
subtotal, currency_code, items.product.id, items.product.collection_id, customer.groups.id Required on create, and restricted per attribute to what the evaluator can compute: the id and group attributes accept only in and nin, currency_code accepts only the equality operators, and gt/gte/lt/lte compare against exactly one value. An unevaluable pair is refused rather than stored.
eq, ne, in, nin, gt, gte, lt, lte Required on create, never empty, at most 200 entries of at most 128 characters. Strings for every attribute including subtotal, because the column is text and the evaluator parses it. On a patch the whole set is REPLACED; there is no add or remove.
Defaults to eligibility, which is the only kind that gates the discount. buy and target describe the two sides of a Buy X Get Y offer and are read ONLY when the application method carries apply_to_quantity; on any other discount they are inert. Not settable on a patch: moving a rule out of eligibility removes the gate.
eligibility, buy, target Merchant notes. Nothing reads it.
Response
Created
