Documentation Index Fetch the complete documentation index at: https://docs.affonso.io/llms.txt
Use this file to discover all available pages before exploring further.
Create a self-service coupon code for an affiliate. This endpoint is public and uses token-based authentication in the request body.
This endpoint does not require API key authentication. Instead, it uses the token in the request body for authentication.
Prerequisites
Self-service coupons must be enabled for the program:
Configure a Coupon Blueprint in your program settings
The blueprint defines the discount type and value for affiliate coupons
Affiliates can only create one coupon per program
Body Parameters
The embed token from POST /v1/embed/token.
The coupon code to create. Must be 3-20 alphanumeric characters. Will be automatically uppercased and special characters removed.
Response
Always true for successful responses.
The created coupon. Show Data Object Properties
The created coupon code (uppercased).
“percentage” or “flat” - determined by the coupon blueprint.
Discount amount - determined by the coupon blueprint.
Validation Rules
Code must be 3-20 alphanumeric characters
Code is converted to uppercase
Non-alphanumeric characters are stripped
Code must be unique within the program
Affiliate can only have one coupon per program
curl -X POST "https://api.affonso.io/v1/embed/coupon" \
-H "Content-Type: application/json" \
-d '{
"token": "a1b2c3d4e5f6789...",
"code": "JOHN20"
}'
Response
Error - Already Has Coupon
Error - Code Taken
Error - Self-Service Not Enabled
Error - Invalid Code Format
Error - Token Expired
{
"success" : true ,
"data" : {
"code" : "JOHN20" ,
"discountType" : "percentage" ,
"discountValue" : 20
}
}
Checking Coupon Status
Use GET /v1/embed/data to check if an affiliate already has a coupon:
const { data } = await fetch ( `https://api.affonso.io/v1/embed/data?token= ${ token } ` )
. then ( r => r . json ());
if ( data . coupon ) {
// Affiliate already has a coupon
console . log ( `Your code: ${ data . coupon . code } ` );
} else if ( data . couponBlueprint ) {
// Can create a coupon
console . log ( 'You can create a coupon!' );
} else {
// Self-service coupons not enabled
console . log ( 'Coupon creation not available' );
}
Once created, coupon codes cannot be changed. Affiliates should choose their code carefully.