Documentation Index
Fetch the complete documentation index at: https://docs.salesive.com/llms.txt
Use this file to discover all available pages before exploring further.
Request
POST /coupons/apply
Content-Type: application/json
x-shop-id: {shopId}
Authorization: Bearer {token}
{
"orderId": "67890abcdef1234567890abc",
"code": "SUMMER20"
}
| Header | Type | Description |
|---|
Content-Type | string | Always set to application/json. |
x-shop-id | string | Shop identifier to associate the user with your store. |
Authorization | string | Bearer token for authenticated user (required). |
This endpoint requires authentication. Only the order owner can apply
coupons to their orders.
Body parameters
| Field | Type | Required | Description |
|---|
orderId | string | Yes | Order ID to apply the coupon to. |
code | string | Yes | Coupon code to apply (case-insensitive). |
Successful response
{
"status": 200,
"success": true,
"message": "Coupon applied successfully",
"data": {
"order": {
"_id": "67890abcdef1234567890abc",
"orderId": 1001,
"subtotal": 1000,
"shippingCost": 50,
"discount": 200,
"total": 850,
"coupon": {
"_id": "67890abcdef1234567890def",
"code": "SUMMER20",
"type": "percentage",
"discount": 20
}
}
}
}
Response fields
| Field | Type | Description |
|---|
order._id | string | Order identifier. |
order.orderId | number | Human-readable order number. |
order.subtotal | number | Order subtotal before shipping and discount. |
order.shippingCost | number | Shipping cost for the order. |
order.discount | number | Discount amount applied by the coupon. |
order.total | number | Final order total (subtotal + shipping - discount). |
order.coupon | object | Applied coupon details. |
Validation checks
The endpoint performs comprehensive validations before applying the coupon:
Order exists and belongs to the authenticated user
Order is in pending status (cannot apply to completed/cancelled orders)
Order does not already have a coupon applied
Coupon exists and is active
Coupon belongs to the specified shop
Coupon is within valid date range
Global usage limit has not been exceeded
Per-user usage limit has not been exceeded
Order meets minimum amount requirement
Side effects
When a coupon is successfully applied:
- Order is updated with the coupon ID and discount amount
- Coupon usage count is incremented globally
- Order total is recalculated with the discount applied
Error responses
Order not found
{
"status": 404,
"success": false,
"message": "Order not found"
}
Unauthorized access
{
"status": 403,
"success": false,
"message": "Unauthorized access to order"
}
Coupon already applied
{
"status": 400,
"success": false,
"message": "Order already has a coupon applied"
}
Invalid order status
{
"status": 400,
"success": false,
"message": "Coupon can only be applied to pending orders"
}
Invalid coupon
{
"status": 404,
"success": false,
"message": "Invalid coupon code"
}
Best practices
Always call the /coupons/verify endpoint first to validate the coupon and
show the discount amount to the user before applying it to the order.
Once a coupon is applied to an order, it cannot be removed or replaced.
Ensure the user confirms the coupon application before calling this
endpoint.
JWT issued by the Salesive Store API for authenticated shoppers.
Optional storefront identifier sent as a header to scope responses to a specific shop. Try It requests remember this value once provided.
Optional identifier that scopes responses to a specific storefront when the referer cannot be inferred.
Order ID to apply the coupon to.
Example:"67890abcdef1234567890abc"
Coupon code to apply (case-insensitive).
Coupon applied successfully.
Example:"Coupon applied successfully"