Skip to main content
Discount codes let you offer percentage-based or fixed-amount discounts on payment links. Create individual codes, bulk-generate batches, and validate codes at checkout time.
Discount code management requires admin permission. The /validate endpoint requires read permission, making it safe to call from client-side checkout flows.

Authentication

Authorization: Bearer asp_xxx
Base URL: https://platform-api.anyspend.com/api/v1

Endpoints

List Discount Codes

GET /discount-codes
read
List all discount codes with optional filtering and pagination.
Search by code string (case-insensitive partial match).
boolean
Filter by active status. Omit to return all codes.
number
Page number for pagination (default: 1).
number
Results per page (default: 20, max: 100).
curl -X GET "https://platform-api.anyspend.com/api/v1/discount-codes?search=SUMMER&active=true&limit=10" \
  -H "Authorization: Bearer asp_xxx"
Response
{
  "success": true,
  "data": [
    {
      "id": "dc_abc123",
      "code": "SUMMER25",
      "type": "percentage",
      "value": 25,
      "payment_link_id": "pl_xyz789",
      "max_uses": 100,
      "current_uses": 42,
      "min_order_amount": "5000000",
      "expires_at": "2026-09-01T00:00:00Z",
      "is_active": true,
      "created_at": "2026-06-01T00:00:00Z",
      "updated_at": "2026-06-01T00:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 1,
    "total_pages": 1
  }
}

Create Discount Code

POST /discount-codes
admin
Create a single discount code.
code
string
required
The discount code string (e.g., SUMMER25). Must be unique. Automatically uppercased.
type
string
required
Discount type: percentage or fixed.
value
number
required
Discount value. For percentage, a number between 1-100. For fixed, the amount in the token’s smallest unit (e.g., 5000000 for 5 USDC).
Restrict this code to a specific payment link. If omitted, the code works on all payment links.
max_uses
number
Maximum number of times this code can be redeemed. Omit for unlimited uses.
min_order_amount
string
Minimum order amount required to use this code, in the token’s smallest unit.
expires_at
string
ISO 8601 expiration timestamp. Omit for a code that never expires.
curl -X POST https://platform-api.anyspend.com/api/v1/discount-codes \
  -H "Authorization: Bearer asp_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "SUMMER25",
    "type": "percentage",
    "value": 25,
    "payment_link_id": "pl_xyz789",
    "max_uses": 100,
    "min_order_amount": "5000000",
    "expires_at": "2026-09-01T00:00:00Z"
  }'
Response
{
  "success": true,
  "data": {
    "id": "dc_abc123",
    "code": "SUMMER25",
    "type": "percentage",
    "value": 25,
    "payment_link_id": "pl_xyz789",
    "max_uses": 100,
    "current_uses": 0,
    "min_order_amount": "5000000",
    "expires_at": "2026-09-01T00:00:00Z",
    "is_active": true,
    "created_at": "2026-02-27T12:00:00Z",
    "updated_at": "2026-02-27T12:00:00Z"
  }
}

Update Discount Code

PATCH /discount-codes/:id
admin
Update an existing discount code. All fields are optional.
curl -X PATCH https://platform-api.anyspend.com/api/v1/discount-codes/dc_abc123 \
  -H "Authorization: Bearer asp_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "max_uses": 200,
    "expires_at": "2026-12-31T23:59:59Z"
  }'

Delete Discount Code

DELETE /discount-codes/:id
admin
Permanently delete a discount code. Active sessions using this code will not be affected.
curl -X DELETE https://platform-api.anyspend.com/api/v1/discount-codes/dc_abc123 \
  -H "Authorization: Bearer asp_xxx"

Validate Discount Code

POST /discount-codes/validate
read
Validate a discount code against a payment link and order amount. Returns the discount details if valid, or an error message explaining why the code is invalid.
code
string
required
The discount code to validate.
The payment link the code is being applied to.
amount
string
required
The order amount in the token’s smallest unit, used to check min_order_amount and calculate the discounted total.
curl -X POST https://platform-api.anyspend.com/api/v1/discount-codes/validate \
  -H "Authorization: Bearer asp_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "SUMMER25",
    "payment_link_id": "pl_xyz789",
    "amount": "20000000"
  }'
Valid Response
{
  "success": true,
  "data": {
    "valid": true,
    "code": "SUMMER25",
    "type": "percentage",
    "value": 25,
    "discount_amount": "5000000",
    "final_amount": "15000000"
  }
}
Invalid Response
{
  "success": true,
  "data": {
    "valid": false,
    "error": "Code has reached maximum number of uses"
  }
}
The validate endpoint does not consume a use. Uses are only counted when a payment is completed with the discount applied.

Batch Create Discount Codes

POST /discount-codes/batch
admin
Bulk-create multiple discount codes at once with shared configuration. Useful for generating promotional campaigns or unique single-use codes.
codes
string[]
required
Array of code strings to create. Each must be unique.
type
string
required
Discount type applied to all codes: percentage or fixed.
value
number
required
Discount value applied to all codes.
Restrict all codes to a specific payment link.
max_uses
number
Maximum uses per code. Set to 1 for single-use codes.
min_order_amount
string
Minimum order amount for all codes.
expires_at
string
ISO 8601 expiration timestamp for all codes.
curl -X POST https://platform-api.anyspend.com/api/v1/discount-codes/batch \
  -H "Authorization: Bearer asp_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "codes": ["PROMO-A1B2", "PROMO-C3D4", "PROMO-E5F6"],
    "type": "fixed",
    "value": 2000000,
    "payment_link_id": "pl_xyz789",
    "max_uses": 1,
    "expires_at": "2026-06-30T23:59:59Z"
  }'
Response
{
  "success": true,
  "data": {
    "created": 3,
    "codes": [
      { "id": "dc_001", "code": "PROMO-A1B2" },
      { "id": "dc_002", "code": "PROMO-C3D4" },
      { "id": "dc_003", "code": "PROMO-E5F6" }
    ]
  }
}

Discount Code Object

FieldTypeDescription
idstringUnique identifier (e.g., dc_abc123)
codestringThe discount code string (uppercased)
typestringpercentage or fixed
valuenumberDiscount value (percentage 1-100, or fixed amount in smallest unit)
payment_link_idstring | nullRestricted payment link, or null for all links
max_usesnumber | nullMaximum redemptions, or null for unlimited
current_usesnumberNumber of times redeemed so far
min_order_amountstring | nullMinimum order amount required
expires_atstring | nullISO 8601 expiration, or null for no expiration
is_activebooleanWhether the code is currently usable
created_atstringISO 8601 creation timestamp
updated_atstringISO 8601 last update timestamp

Validation Rules

A discount code is considered invalid if any of the following are true:
ConditionError Message
Code does not existInvalid discount code
Code is inactive (is_active: false)Discount code is not active
Code has expiredDiscount code has expired
current_uses >= max_usesCode has reached maximum number of uses
Code is restricted to a different payment linkCode is not valid for this payment link
Order amount is below min_order_amountOrder amount is below minimum required