Create a new promotional coupon for an affiliate. The coupon is created at your payment provider and linked to the affiliate in Affonso.
Coupon creation rules vary by payment provider:
- DODO: Only supports percentage discounts
- CREEM: Requires at least one product_id
- All providers:
duration_in_months required when duration is repeating
- All providers:
currency required when discount_type is fixed
Body Parameters
The ID of the affiliate who will own this coupon.
The coupon code. Must be 1-50 characters, alphanumeric characters and hyphens only. Will be converted to uppercase.
Type of discount to apply. Valid values: percentage, fixed.
The discount amount. For percentage: value between 0-100. For fixed: the discount amount in the specified currency.
How long the discount applies. Valid values:
forever: Discount applies to all future invoices
once: Discount applies only to the first invoice
repeating: Discount repeats for a specified number of months
Number of months the discount repeats. Required when duration is repeating.
Three-letter currency code (e.g., USD, EUR, GBP). Required when discount_type is fixed.
Array of product IDs to restrict this coupon to. Leave empty or omit to apply to all products.
Response
The response includes the created coupon object.
Always true for successful responses
The created coupon object.Show Data Object Properties
Unique identifier for the coupon
The coupon code (uppercase)
The ID of the affiliate who owns this coupon
Type of discount: percentage or fixed
How long the discount applies: forever, once, or repeating
Number of months the discount repeats (only applicable when duration is repeating)
Three-letter currency code (only applicable when discount_type is fixed)
Array of product IDs this coupon is restricted to
ISO 8601 timestamp of when the coupon was created
curl -X POST "https://api.affonso.io/v1/coupons" \
-H "Authorization: Bearer sk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"affiliate_id": "aff_123",
"code": "SAVE25",
"discount_type": "percentage",
"discount_value": 25,
"duration": "forever"
}'
{
"success": true,
"data": {
"id": "cpn_abc123",
"code": "SAVE25",
"affiliate_id": "aff_123",
"discount_type": "percentage",
"discount_value": 25,
"duration": "forever",
"duration_in_months": null,
"currency": null,
"product_ids": [],
"created_at": "2024-01-15T10:30:00Z"
}
}
Error Responses
Returned when a coupon with the same code already exists.
Returned when the payment provider fails to create the coupon.