Skip to main content
POST
/
v1
/
embed
/
coupon
curl -X POST "https://api.affonso.io/v1/embed/coupon" \
  -H "Content-Type: application/json" \
  -d '{
    "token": "a1b2c3d4e5f6789...",
    "code": "JOHN20"
  }'
{
  "success": true,
  "data": {
    "code": "JOHN20",
    "discountType": "percentage",
    "discountValue": 20
  }
}
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:
  1. Configure a Coupon Blueprint in your program settings
  2. The blueprint defines the discount type and value for affiliate coupons
  3. Affiliates can only create one coupon per program

Body Parameters

token
string
required
The embed token from POST /v1/embed/token.
code
string
required
The coupon code to create. Must be 3-20 alphanumeric characters. Will be automatically uppercased and special characters removed.

Response

success
boolean
Always true for successful responses.
data
object
The created coupon.

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"
  }'
{
  "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.