Validate a coupon code and preview the discount that would be applied.
POST/v2/projects/{project_id}/coupons/validate Path Parameters
The unique identifier of the project.
Request Body
The coupon code to validate.
The user ID attempting to use the coupon.
The original amount before discount.
The currency of the amount (e.g., USD).
curl -X POST "https://api.botsubscription.com/v2/projects/f47ac10b-58cc-4372-a567-0e02b2c3d479/coupons/validate" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"code": "SUMMER2024",
"user_id": "user_123456789",
"amount": 29.99,
"currency": "USD",
"plan_id": "plan_abc123"
}'
const project_id = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';
const response = await fetch(`https://api.botsubscription.com/v2/projects/${project_id}/coupons/validate`, {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
code: 'SUMMER2024',
user_id: 'user_123456789',
amount: 29.99,
currency: 'USD',
plan_id: 'plan_abc123'
})
});
const data = await response.json();
import requests
project_id = 'f47ac10b-58cc-4372-a567-0e02b2c3d479'
response = requests.post(
f'https://api.botsubscription.com/v2/projects/{project_id}/coupons/validate',
headers={
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
json={
'code': 'SUMMER2024',
'user_id': 'user_123456789',
'amount': 29.99,
'currency': 'USD',
'plan_id': 'plan_abc123'
}
)
data = response.json()
$project_id = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/coupons/validate");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer YOUR_TOKEN',
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'code' => 'SUMMER2024',
'user_id' => 'user_123456789',
'amount' => 29.99,
'currency' => 'USD',
'plan_id' => 'plan_abc123'
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
Coupon eligibleapplication/json
{
"ok": true,
"request_id": "11111111-1111-1111-1111-111111111111",
"method": "POST",
"path": "/v2/projects/YOUR_PROJECT_ID/coupons/validate",
"code": 200,
"data": {
"coupon_id": "11111111-1111-1111-1111-111111111111",
"eligible": true,
"reasons": [],
"original_amount": "29.99",
"applied_amount": "6",
"final_amount": "23.99",
"currency": "USD"
}
}
Coupon not eligibleapplication/json
{
"ok": true,
"request_id": "11111111-1111-1111-1111-111111111111",
"method": "POST",
"path": "/v2/projects/YOUR_PROJECT_ID/coupons/validate",
"code": 200,
"data": {
"coupon_id": "11111111-1111-1111-1111-111111111111",
"eligible": false,
"reasons": ["Coupon has expired"]
}
}
Coupon not foundapplication/json
{
"ok": false,
"request_id": "11111111-1111-1111-1111-111111111111",
"method": "POST",
"path": "/v2/projects/YOUR_PROJECT_ID/coupons/validate",
"code": 404,
"error": {
"error_code": "NOT_FOUND",
"message": "Requested resource could not be found"
}
}
Last updated: