Skip to main content
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

Headers

HeaderRequiredDescription
X-Embed-KeyYesYour store’s embed public key
Content-TypeYesapplication/json

Request Body

FieldTypeRequiredDescription
codestringYesThe coupon code to validate
product_idintegerYesThe product ID to apply the coupon to
quantityintegerYesThe 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

FieldTypeDescription
coupon_idintegerInternal coupon ID
codestringThe coupon code
typestringCoupon type: percentage or fixed
amountfloatThe coupon value (percentage or fixed amount)
discount_amountfloatThe calculated discount for the given product and quantity
payment_restrictionsarrayList 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"
}