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.

Info

Discount code management requires admin permission. The /validate endpoint requires read permission, making it safe to call from client-side checkout flows.

Authentication

bash
Authorization: Bearer asp_xxx

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

Endpoints

List Discount Codes

List all discount codes with optional filtering and pagination.

searchstringpath

Search by code string (case-insensitive partial match).

activebooleanpath

Filter by active status. Omit to return all codes.

pagenumberpath

Page number for pagination (default: 1).

limitnumberpath

Results per page (default: 20, max: 100).

bash
curl -X GET "https://platform-api.anyspend.com/api/v1/discount-codes?search=SUMMER&active=true&limit=10" \ -H "Authorization: Bearer asp_xxx"

Response

json
{ "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

Create a single discount code.

codestringrequiredpath

The discount code string (e.g., SUMMER25). Must be unique. Automatically uppercased.

typestringrequiredpath

Discount type: percentage or fixed.

valuenumberrequiredpath

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).

payment_link_idstringpath

Restrict this code to a specific payment link. If omitted, the code works on all payment links.

max_usesnumberpath

Maximum number of times this code can be redeemed. Omit for unlimited uses.

min_order_amountstringpath

Minimum order amount required to use this code, in the token's smallest unit.

expires_atstringpath

ISO 8601 expiration timestamp. Omit for a code that never expires.

bash
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

json
{ "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

Update an existing discount code. All fields are optional.

bash
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

Permanently delete a discount code. Active sessions using this code will not be affected.

bash
curl -X DELETE https://platform-api.anyspend.com/api/v1/discount-codes/dc_abc123 \ -H "Authorization: Bearer asp_xxx"

Validate Discount Code

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.

codestringrequiredpath

The discount code to validate.

payment_link_idstringrequiredpath

The payment link the code is being applied to.

amountstringrequiredpath

The order amount in the token's smallest unit, used to check min_order_amount and calculate the discounted total.

bash
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

json
{ "success": true, "data": { "valid": true, "code": "SUMMER25", "type": "percentage", "value": 25, "discount_amount": "5000000", "final_amount": "15000000" }}

Invalid Response

json
{ "success": true, "data": { "valid": false, "error": "Code has reached maximum number of uses" }}
Note

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

Bulk-create multiple discount codes at once with shared configuration. Useful for generating promotional campaigns or unique single-use codes.

codesstring[]requiredpath

Array of code strings to create. Each must be unique.

typestringrequiredpath

Discount type applied to all codes: percentage or fixed.

valuenumberrequiredpath

Discount value applied to all codes.

payment_link_idstringpath

Restrict all codes to a specific payment link.

max_usesnumberpath

Maximum uses per code. Set to 1 for single-use codes.

min_order_amountstringpath

Minimum order amount for all codes.

expires_atstringpath

ISO 8601 expiration timestamp for all codes.

bash
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

json
{ "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
Ask a question... ⌘I