Validate a coupon code against a specific product and quantity, and get the calculated discount amount.
Apply Coupon
This is a public endpoint. It requires the X-Embed-Key header but no customer authentication.
POST /api/embed/apply-coupon
| Header | Required | Description |
|---|
X-Embed-Key | Yes | Your store’s embed public key |
Content-Type | Yes | application/json |
Request Body
| Field | Type | Required | Description |
|---|
code | string | Yes | The coupon code to validate |
product_id | integer | Yes | The product ID to apply the coupon to |
quantity | integer | Yes | The purchase quantity (min: 1) |
Example Request
curl -X POST "https://embed.rmz.gg/api/embed/apply-coupon" \
-H "X-Embed-Key: your_embed_public_key" \
-H "Content-Type: application/json" \
-d '{
"code": "SAVE20",
"product_id": 42,
"quantity": 1
}'
Success Response (200)
{
"success": true,
"data": {
"coupon_id": 15,
"code": "SAVE20",
"type": "percentage",
"amount": 20.0,
"discount_amount": 29.80,
"payment_restrictions": []
}
}
Response Fields
| Field | Type | Description |
|---|
coupon_id | integer | Internal coupon ID |
code | string | The coupon code |
type | string | Coupon type: percentage or fixed |
amount | float | The coupon value (percentage or fixed amount) |
discount_amount | float | The calculated discount for the given product and quantity |
payment_restrictions | array | List of payment methods this coupon is restricted to (empty array = no restrictions) |
If payment_restrictions is not empty, the customer can only use the listed payment methods when this coupon is applied. Display the restrictions in your UI to avoid confusion at checkout.
Error Responses
Validation error (422)
{
"success": false,
"message": "Invalid request",
"errors": {
"code": ["The code field is required."],
"product_id": ["The product id field is required."],
"quantity": ["The quantity field is required."]
}
}
Invalid coupon (400)
{
"success": false,
"message": "Invalid coupon"
}
Coupon expired or inactive (400)
{
"success": false,
"message": "Coupon is not active"
}
Coupon usage limit reached (400)
{
"success": false,
"message": "Coupon has reached maximum uses"
}
Minimum cart value not met (400)
{
"success": false,
"message": "Minimum order value is 100"
}
Product not eligible (400)
{
"success": false,
"message": "This coupon is not valid for this product"
}