Create coupon
Add a coupon
POST
https://s.zo.sa/api/public/v1 /coupons Scope
marketing.read_writeIdempotency-Key supportedRequest
Headers
| Name | Type | Required | Description |
|---|---|---|---|
Idempotency-Key | string | 1 to 120 visible ASCII characters. A write sent again with the same key runs once; the retry gets the first answer back with the header Idempotent-Replayed: true. Use a new key for each new write. 1 to 120 characters |
Request body
A coupon to create (POST: code, type and value required) or change (PATCH: only the keys sent change). The same rules as the dashboard's coupons page.
codestringrequiredUnique in the store; saved in capitals.typestringrequiredvalueintegerrequiredA whole percent (at most 100) for percent; halalas for fixed.min_subtotalintegernullableHalalas.max_discountintegernullableHalalas.free_shippingbooleanusage_limitintegernullableper_customer_limitintegernullablestarts_atstring (date)nullableThe coupon works from the start of this day in Riyadh.ends_atstring (date)nullableUntil the last second of this day in Riyadh; not before starts_at.is_activebooleanAn expired coupon is switched back on only with an ends_at still ahead.applies_tostringproducts needs product_ids, categories needs category_ids.product_idsarray of integersnullableProducts of this store.category_idsarray of integersnullableCategories of this store.exclude_sale_itemsbooleanpayment_methodsarray of stringsnullablePayment method codes the coupon is limited to.first_order_onlybooleanexclude_walletbooleanshow_in_cartbooleannotestringnullable
cURL
curl -sS -X POST "https://s.zo.sa/api/public/v1/coupons" \
-H "Authorization: Bearer $ZO_API_KEY" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: erp-coupon-WELCOME10" \
-d '{
"code": "WELCOME10",
"type": "percent",
"value": 10
}'JavaScript
const response = await fetch('https://s.zo.sa/api/public/v1/coupons', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.ZO_API_KEY}`,
Accept: 'application/json',
'Content-Type': 'application/json',
'Idempotency-Key': 'erp-coupon-WELCOME10',
},
body: JSON.stringify({
"code": "WELCOME10",
"type": "percent",
"value": 10
}),
});
console.log(response.status, await response.json());PHP
<?php
$ch = curl_init('https://s.zo.sa/api/public/v1/coupons');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('ZO_API_KEY'),
'Accept: application/json',
'Content-Type: application/json',
'Idempotency-Key: erp-coupon-WELCOME10',
],
CURLOPT_POSTFIELDS => json_encode([
'code' => 'WELCOME10',
'type' => 'percent',
'value' => 10,
]),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
echo $status, PHP_EOL, $body, PHP_EOL;Python
import os
import requests
response = requests.post(
"https://s.zo.sa/api/public/v1/coupons",
headers={
"Authorization": f"Bearer {os.environ['ZO_API_KEY']}",
"Accept": "application/json",
"Idempotency-Key": "erp-coupon-WELCOME10",
},
json={
"code": "WELCOME10",
"type": "percent",
"value": 10,
},
timeout=30,
)
print(response.status_code, response.json())10% off. A percent value is at most 100; a fixed value is in halalas.
{
"data": {
"id": 9,
"code": "WELCOME10",
"type": "percent",
"value": 10,
"min_subtotal": null,
"max_discount": null,
"free_shipping": false,
"usage_limit": null,
"per_customer_limit": null,
"uses": 0,
"starts_at": null,
"ends_at": null,
"is_active": true,
"status": "active",
"created_at": "2026-11-23T08:00:00Z",
"updated_at": "2026-11-23T08:00:00Z"
}
}Example.
Responses
201The new coupon.
Response schema
dataobjectrequired16 fields
idintegerrequiredcodestringrequiredtypestringrequiredvalueintegerrequiredA whole percent for type percent; halalas for type fixed.min_subtotalintegerrequirednullableHalalas.max_discountintegerrequirednullableHalalas.free_shippingbooleanrequiredusage_limitintegerrequirednullableper_customer_limitintegerrequirednullableusesintegerrequiredHow many times the coupon was used.starts_atstring (date-time)requirednullableends_atstring (date-time)requirednullableis_activebooleanrequiredstatusstringrequiredcreated_atstring (date-time)requiredupdated_atstring (date-time)required
401Missing, unknown, revoked or expired key.
An error object: {"error": {"code", "message", "fields"}}.
402The store's plan does not include this feature (error code feature_locked, with the feature and the plan that has it). Every operation answers it with feature public_api when the key's store is not on the Pro plan.
An error object: {"error": {"code", "message", "fields"}}.
403The key lacks the scope (code insufficient_scope, naming it in scope), the caller's address is not allowed (ip_not_allowed), or the store is suspended (store_suspended: reads stay allowed, every write answers this).
An error object: {"error": {"code", "message", "fields"}}.
409A write with the same Idempotency-Key is still running (code duplicate_request); retry shortly.
An error object: {"error": {"code", "message", "fields"}}.
422validation_failed (fields names the input; a code the store already has is refused on code).
An error object: {"error": {"code", "message", "fields"}}.
429Too many requests (code rate_limited); see Retry-After.
An error object: {"error": {"code", "message", "fields"}}.