Create a Coupon
Endpoint
POST /coupons/create
Required parameters
code-VARCHAR(100)- The coupon code (must be unique and at least 2 characters). Case-insensitive.-
type-VARCHAR(10)- The discount type, values can be:percentage- Percentage discount (e.g., 20 for 20% off)fixed- Fixed amount discount (e.g., 10 for $10 off)
amount-DECIMAL- The discount amount. For percentage type, must be between 0.1 and 100. For fixed type, must be between 0.1 and 999999.99.
Optional parameters
is_storewide-BOOLEAN- Whether the coupon applies to all products. Defaults totrue. Iffalse, you must provideproducts.products-ARRAY- List of product IDs to apply this coupon to. Required ifis_storewideisfalse.is_live-BOOLEAN- Whether the coupon is active and can be used. Defaults tofalse.limit-INT- Maximum number of times this coupon can be redeemed. Leave blank for unlimited.duration_in_months-INT- For subscription products only. Number of months the discount applies. After this period, regular pricing resumes. Leave blank to apply discount indefinitely.start-DATETIME- When the coupon becomes valid. ISO 8601 format (e.g.,2023-12-31T23:59:59Z). Leave blank for no start date.end-DATETIME- When the coupon expires. ISO 8601 format (e.g.,2024-12-31T23:59:59Z). Must be afterstartif both are provided. Leave blank for no expiration.affiliate-VARCHAR(25)- ID of the affiliate to associate this coupon with. Leave blank if not applicable.requires_subscription_product-VARCHAR(25)- ID of a subscription product. If set, this coupon can only be used by active subscribers of that product. Leave blank if not applicable.
Example request
curl https://api.zylvie.com/coupons/create \
-X POST \
-h "Authorization: Bearer e97f0aafe4884bc380c81fdb2347dc55" \
-h "Content-Type: application/json" \
-d '{
"code": "SUMMER2024",
"type": "percentage",
"amount": 25,
"is_storewide": true,
"is_live": true,
"limit": 100,
"start": "2024-06-01T00:00:00Z",
"end": "2024-08-31T23:59:59Z"
}'
Example response
{
"id": "8x9Pqm3N",
"created": "2024-01-15T10:30:00Z",
"code": "SUMMER2024",
"type": "percentage",
"amount": 25.0,
"is_storewide": true,
"is_live": true,
"limit": 100,
"duration_in_months": null,
"start": "2024-06-01T00:00:00Z",
"end": "2024-08-31T23:59:59Z",
"redemption_count": 0,
"products": [],
"affiliate": null,
"requires_subscription_product": null
}