Redeem/Revert

Learn how to use the Redeem/Revert Coupon API to update the coupon code status, ensuring accurate application and reversals during transactions.

Overview

The Redeem/Revert Coupon API allows you to manage coupon code redemption and reversal during transactions. This API ensures accurate tracking of coupon usage by updating its status based on the transaction outcome, whether successful or canceled.

You can integrate this API at critical touchpoints such as payment processing or order cancellation flows. Upon execution, CleverTap processes the coupon redemption or reversal request and returns a response indicating the updated status of the coupon code for the specified user.

You can use this API in the following cases:

  • A user completes a transaction, and the coupon code needs to be redeemed.
  • A user cancels an order, and the redeemed coupon needs to be reverted to be used again.
  • Payment failure after the coupon code is redeemed.
  • Any other custom checkpoints in the user journey that require coupon redemption or reversal during transaction management.

Base URL

The following is a sample base URL:

https://<region>.api.clevertap.com/1/promo/coupons/apply

For region-specific endpoints, refer to Region.

HTTP Method

POST

Headers

For more information about API headers, refer to Headers.

Query Parameters

The following table lists the query parameters.

ParameterDescriptionRequired/OptionalTypeExample Value
identityUnique identifier for the user. Mandatory for campaign user coupon validation to determine the source of the coupon issued. If not provided, the API returns the error "identity is required".Requiredstringuser0123
typeSpecifies the action to be taken. Use redeem to apply a coupon or revert to cancel a redeemed coupon. If missing or invalid, the API returns an error indicating the type must be either redeem or revert.Requiredstringredeem or revert

Body Parameters

The body parameters define the structure and data required to redeem or revert a coupon. The request body accepts couponCode and couponId as top-level fields alongside the order object. The items array is nested inside the order object.

Top-Level Body Parameters

The following table lists the top-level body parameters.

ParameterDescriptionRequired/OptionalTypeExample Value
couponCodeUnique coupon code to redeem or revert. Always required regardless of coupon type.RequiredstringDIWALI100
couponIdCoupon ID generated against the coupon code. Required whentype=revert; not applicable for type=redeem.Required for type=revertinteger1695
orderObject containing order and item details. See the order Object section below.Requiredobject
📘

Coupon Code Handling

couponCode is always required for both fixed code and bulk code coupons. For bulk code coupons, the couponCode must match the specific code assigned to the user.

order Object

The order object provides information about the overall order. If the order object is not included, the API cannot process the request, as coupon applicability and calculations depend on these order details.

The following table lists the order object parameters.

ParameterDescriptionRequired/OptionalTypeExample Value
orderIdUnique identifier for the order being placed.Requiredstringabcd12345
saleMrpTotalSum of the original price of all items, calculated as MRP × quantity.Optionalnumeric500
saleAmountSum of the selling price of all items, calculated as unitPrice × quantity.Required for type=redeemnumeric300
saleChannelSource through which the sale is made.Optionalstringonline
locationLocation where the sale is made.OptionalstringIndia
locationIdUnique ID assigned to the location.OptionalstringIND
orderShippingShipping charges for the order.Optionalnumeric30
orderStatusStatus of the transaction: pending (initiated but not completed), completed (successfully completed), or reverted (rolled back).Required for type=redeemstringpending
paymentModeMode of payment used for the transaction (for example, credit_card, debit_card, net_banking).Optionalstringcredit_card
cartQuantityTotal quantity of items in the cart.Optionalnumeric4
itemsArray of item objects nested inside order. See the items Array section below.Requiredarray of objects
metadataCustom key-value pairs for advanced coupon validations at the order level.Optionalobject{"customerType": "guests"}

items Array (nested inside order)

The items array is nested inside the order object and provides details about individual items in the cart.

The following table lists the items object parameters.

ParameterDescriptionRequired/OptionalTypeExample Value
productIdUnique identifier for the product in your application.Requiredstringabc_124
skuStock Keeping Unit (SKU) assigned to the product.Optionalstring124
itemNameName of the product.OptionalstringCotton Shirt
categoryCategory of the product.Optionalstringshirts
subCategorySubcategory of the product.Optionalstringcotton shirts
brandBrand of the product.Optionalstringsuperdry
unitPriceSelling price of the product.Requirednumeric80
mrpOriginal MRP of the product.Optionalnumeric700
quantityQuantity of the product in the cart.Optionalinteger12
metadataCustom key-value pairs for advanced item-level coupon validations.Optionalobject{"color": "blue"}

metadata Object

The metadata object allows you to include additional custom key-value pairs for advanced coupon validations. It can be passed within both the order and items objects.

The following table lists the metadata object parameters.

ParameterDescriptionRequired/OptionalTypeExample Value
keyMetadata property name (for example, color, size, supplier).Optionalstringsize
valueMetadata property value (for example, Red, Large, Supplier A).Optionalstringlarge

Example Request

The following are sample requests to the Redeem/Revert Coupon API, showing the headers needed to authenticate the request.

curl -X POST "https://<region>.api.clevertap.com/1/promo/coupons/apply?identity=krishna123&type=redeem" \
-H "X-CleverTap-Account-Id: ACCOUNT_ID" \
-H "X-CleverTap-Passcode: PASSCODE" \
-H "Content-Type: application/json" \
-d '{
    "couponCode": "SALE100",
    "order": {
        "orderId": "order123349",
        "saleMrpTotal": 399,
        "saleAmount": 101,
        "saleChannel": "online",
        "location": "BLR",
        "locationId": "IND",
        "orderStatus": "pending",
        "items": [
            {
                "productId": "123456",
                "sku": "124",
                "itemName": "Cotton Shirt",
                "category": "shirts",
                "subCategory": "cotton shirts",
                "brand": "superdry",
                "unitPrice": 300,
                "mrp": 300,
                "quantity": 3,
                "metadata": {
                    "color": "blue"
                }
            },
            {
                "productId": "123457",
                "sku": "125",
                "itemName": "Chino Trouser",
                "category": "trousers",
                "subCategory": "",
                "brand": "levis",
                "unitPrice": 100,
                "mrp": 100,
                "quantity": 1,
                "metadata": {
                    "color": "khaki"
                }
            }
        ],
        "metadata": {
            "customerType": "guests"
        }
    }
}'
curl -X POST "https://<region>.api.clevertap.com/1/promo/coupons/apply?identity=krishna123&type=revert" \
-H "X-CleverTap-Account-Id: ACCOUNT_ID" \
-H "X-CleverTap-Passcode: PASSCODE" \
-H "Content-Type: application/json" \
-d '{
    "couponCode": "SALE100",
    "couponId": 1695,
    "order": {
        "orderId": "order123349",
        "saleMrpTotal": 399,
        "saleAmount": 101,
        "saleChannel": "online",
        "location": "BLR",
        "locationId": "IND",
        "orderStatus": "reverted",
        "items": [
            {
                "productId": "123456",
                "sku": "124",
                "itemName": "Cotton Shirt",
                "category": "shirts",
                "subCategory": "cotton shirts",
                "brand": "superdry",
                "unitPrice": 300,
                "mrp": 300,
                "quantity": 3,
                "metadata": {
                    "color": "blue"
                }
            },
            {
                "productId": "123457",
                "sku": "125",
                "itemName": "Chino Trouser",
                "category": "trousers",
                "subCategory": "",
                "brand": "levis",
                "unitPrice": 100,
                "mrp": 100,
                "quantity": 1,
                "metadata": {
                    "color": "khaki"
                }
            }
        ],
        "metadata": {
            "customerType": "guests"
        }
    }
}'

Find CleverTap Account ID and Passcode

You can find the CleverTap Account ID and Passcode from the CleverTap dashboard by navigating to Settings > Project.

Find CleverTap Project Details

Example Response

The following are sample responses for redeem and revert requests.

{
    "status": "success",
    "records": [
        {
            "couponTimeframe": [
                {
                    "timeSlot": {
                        "startTime": "00:00AM",
                        "endTime": "11:59PM"
                    },
                    "validationDay": "All"
                }
            ],
            "couponName": "SALE100",
            "couponExpiry": 32494151843,
            "couponCodeId": 2255,
            "totalRedemptionUnlimited": true,
            "isApplicable": true,
            "description": "",
            "message": "",
            "couponExpiryNever": true,
            "termsAndConditions": [],
            "discountEffect": {
                "discountRate": 99,
                "rewardType": "cashback",
                "discountType": "entireOrder",
                "discountAppliedOn": "saleAmount",
                "discountValue": "absolute"
            },
            "totalRedemptionLeft": 0,
            "couponSavings": {
                "customPropertyDiscount": null,
                "orderDiscount": 0,
                "shippingDiscount": 0,
                "orderCashbackPoints": 0,
                "order": {
                    "saleAmount": 2300,
                    "metadata": {
                        "customerType": "premium",
                        "transactionId": "UPI123456789"
                    },
                    "saleMrpTotal": 2500,
                    "orderId": "order123349",
                    "orderStatus": "pending",
                    "itemsTotalQuantity": 0,
                    "itemsMrpTotal": 0,
                    "saleChannel": "online",
                    "orderShipping": 100,
                    "locationId": "IND",
                    "location": "BLR",
                    "items": [],
                    "orderNetAmount": 2300,
                    "itemsSaleAmount": 0
                }
            },
            "bestCoupon": "",
            "identity": "j10393",
            "requestId": "",
            "redemptionActivationDate": 1756405800,
            "userRedemptionUnlimited": false,
            "redemptionStatus": true,
            "couponCode": "SALE100",
            "userRedemptionLeft": 1
        }
    ]
}
{
    "status": "success",
    "records": [
        {
            "couponTimeframe": null,
            "couponName": "",
            "couponExpiry": 0,
            "couponCodeId": 2255,
            "totalRedemptionUnlimited": false,
            "isApplicable": false,
            "description": "",
            "message": "",
            "couponExpiryNever": false,
            "termsAndConditions": null,
            "discountEffect": {
                "discountRate": 0,
                "rewardType": "cashback",
                "discountType": "",
                "discountAppliedOn": "",
                "discountValue": ""
            },
            "totalRedemptionLeft": 0,
            "couponSavings": {
                "customPropertyDiscount": null,
                "orderDiscount": 0,
                "shippingDiscount": 0,
                "orderCashbackPoints": 0,
                "order": {
                    "saleAmount": 0,
                    "metadata": null,
                    "saleMrpTotal": 0,
                    "orderId": "order123349",
                    "orderStatus": "",
                    "itemsTotalQuantity": 0,
                    "itemsMrpTotal": 0,
                    "saleChannel": "",
                    "orderShipping": 0,
                    "locationId": "",
                    "location": "",
                    "items": null,
                    "orderNetAmount": 0,
                    "itemsSaleAmount": 0
                }
            },
            "bestCoupon": "",
            "identity": "j10393",
            "requestId": "",
            "redemptionActivationDate": 0,
            "userRedemptionUnlimited": false,
            "redemptionStatus": false,
            "couponCode": "SALE100",
            "userRedemptionLeft": 0
        }
    ]
}

The response structure is the same as the Fetch Coupon API response. The following differences apply for this endpoint:

  • The identity field in the response returns CleverTap's internal J-ID (for example, j10393), which is the internal numeric user ID resolved from the caller's input identity. This is not the same as the identity value passed in the query parameter. Do not compare the response identity against your input value.
  • The bestCoupon field returns an empty string ("") in both redeem and revert responses. Best-coupon ranking is not computed for this endpoint.

Understanding API Response

The Redeem/Revert Coupon API shares several behavior points with the Validate Coupon API. Refer to the Validate Coupon API Behavior section for applicable rules, including:

  • Identity validation
  • Order and Item Object validation
  • Optional parameters validation
  • Metadata validation
  • Coupon code or coupon ID validation
  • Day-specific coupon availability
  • Case sensitivity of coupon codes

The following are additional behaviors specific to the Redeem/Revert API.

ScenarioBehavior
Coupon redeemed for non-logged-in usersThe API returns an error message, as coupons cannot be redeemed by non-logged-in users.
Coupon redemption against duplicate order IDThe API returns an error message if a coupon is redeemed against the same order ID as a normal coupon.
Reverting a coupon with a mismatched order IDThe API returns an error message if a coupon is reverted without matching the original redeemed order ID.
Stacking normal and customProperty couponsUsers can redeem one normal coupon (applying discounts to predefined cart conditions such as entireOrder, cartExcluding, or selectedItems) with multiple customProperty coupons (applying discounts based on custom attributes) against the same order ID.
Stacking normal couponsUsers cannot redeem the same or different normal coupons multiple times against the same order ID.
Stacking customProperty couponsUsers cannot redeem the same customProperty coupon multiple times against the same order ID.
Duplicate order IDsThe API validates duplicate order IDs based on the combination of coupon type and order ID.

Errors

To know about the errors applicable to the Redeem/Revert Coupon API, refer to API Error Cases.


Did this page help you?
CleverTap Ask AI Widget (CSP-Safe)