Validate Coupon

Learn how to use the Validate Coupon API to verify coupon codes and enable a smooth checkout experience for your customers.

Overview

The Validate Coupon API enables you to verify the validity and applicability of a coupon code entered by users at checkout. Verifying coupon details against cart and product metadata ensures accurate discounts and a seamless shopping experience.

You can integrate this API at relevant touchpoints within the application or website. Upon successful validation, CleverTap validates if the coupon code is redeemable and returns the result in a structured response.

You can use this API in the following cases:

  • When the user applies the coupon code to the cart.
  • When a user enters the coupon code manually.
  • When a user modifies the cart details after applying the coupon.
  • Any other custom checkpoints in the user journey while completing a transaction.

Base URL

The following is a sample base URL:

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

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
identityThe unique identifier for the user. Mandatory for campaign user coupon validation to determine the source of the coupon issued.Optional for All Users Coupon, Required for Campaign Users Couponstringuser123
📘

Identity Not Passed

When identity is not passed for a campaign user coupon, the system returns an error message indicating the missing identity or prompts the user to log in to redeem the coupon code.

Body Parameters

The body parameters define the structure and data required for coupon validation. The request body accepts a top-level couponCode field and an order object. The items array is nested inside the order object.

The following table lists the top-level body parameters.

ParameterDescriptionRequired/OptionalTypeExample Value
couponCodeThe unique coupon code to validate. Coupon code validation is case-insensitive, so FLAT500 and flat500 are treated as the same code.RequiredstringFLAT500
orderObject containing order and item details. See the order Object section below.Requiredobject

order Object

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

The following table lists the order object parameters.

ParameterDescriptionRequired/OptionalTypeExample Value
orderIdUnique ID 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.Requirednumeric300
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
orderStatusCurrent status of the transaction. Accepted values: pending (order initiated but not completed), completed (order successfully completed), reverted (order rolled back).Optionalstringpending
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. If the items array is not included, the API cannot process the validation correctly, as it relies on item-specific information such as productId, unitPrice, and quantity to validate and apply coupons.

The following table lists the items object parameters.

ParameterDescriptionRequired/OptionalTypeExample Value
productIdUnique identifier for the product in the 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.Requirednumeric12
metadataCustom key-value pairs for advanced item-level coupon validations.Optionalobject{"color": "blue"}
📘

order and items Object Validation

The following scenarios apply when validating order and item objects:

  • If the order and items objects are not passed, the API returns an error message indicating missing order or item objects.
  • If the mandatory keys for the order and items objects are missing, the API returns an error message indicating the missing mandatory keys.
  • If the mandatory keys for the order and items objects are passed but contain empty values, the API returns an error message indicating the invalid input.
  • If the complete order and items object details are passed, the API validates the coupon based on the cart or product properties and returns the isApplicable status (true or false) along with a validation message.

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 is a sample request to the Validate Coupon API, showing the headers needed to authenticate the request.

curl -X POST "https://<region>.api.clevertap.com/1/promo/coupons/validate?identity=krishna123" \
-H "X-CleverTap-Account-Id: ACCOUNT_ID" \
-H "X-CleverTap-Passcode: PASSCODE" \
-H "Content-Type: application/json" \
-d '{
    "couponCode": "FLAT500",
    "order": {
        "orderId": "order12345",
        "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"
        }
    }
}'

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 is a sample response.

{
    "status": "success",
    "records": [
        {
            "couponTimeframe": [
                {
                    "timeSlot": {
                        "startTime": "00:00AM",
                        "endTime": "11:59PM"
                    },
                    "validationDay": "All"
                }
            ],
            "couponName": "FLAT500",
            "couponExpiry": 32494151843,
            "couponCodeId": 1003,
            "totalRedemptionUnlimited": true,
            "isApplicable": true,
            "description": "This offer is applicable on order above $100",
            "message": "",
            "couponExpiryNever": true,
            "termsAndConditions": [
                "Applicable on order above $100",
                "Valid till may end"
            ],
            "discountEffect": {
                "discountRate": 100,
                "rewardType": "discount",
                "discountType": "entireOrder",
                "discountAppliedOn": "saleAmount",
                "discountValue": "absolute"
            },
            "totalRedemptionLeft": 0,
            "couponSavings": { "...": "..." },
            "bestCoupon": "",
            "identity": "j541399",
            "requestId": "",
            "redemptionActivationDate": 1755446400,
            "userRedemptionUnlimited": false,
            "redemptionStatus": true,
            "couponCode": "FLAT500",
            "userRedemptionLeft": 1
        }
    ]
}

The response structure is the same as the Fetch Coupon API response. The following difference applies to the validate endpoint: the bestCoupon field returns an empty string ("") in the validate response, rather than "Yes" or "No". This is because the best-coupon ranking is not computed during single-coupon validation.

Understanding API Responses

The API response varies depending on the input payload, metadata, coupon configuration, and user identity. The following table describes the specific scenarios and their expected outcomes.

ScenarioBehavior
Optional parameters validationIf validation rules apply to optional parameters that are not provided in the request, the API still validates them and returns an error message.
Metadata validationCustom fields must be provided as key-value pairs within the metadata object of the order or items object. The API validates the metadata properties set in the coupon and returns the isApplicable status (true or false) with a validation message, regardless of whether metadata details are passed.
Coupon details not providedThe API returns an error message indicating that coupon details are mandatory.
Coupon expiredThe API returns an error message indicating the coupon is expired.
Day-specific coupon availabilityIf a coupon is not valid on the current day, the coupon is returned with isApplicable as false and an error message indicating the day restriction.
Case-sensitive coupon codesThe API is case-insensitive when validating coupon codes. For example, KMN123 and kmn123,both are considered valid codes.

Errors

To know about the errors applicable to the Validate Coupon API, refer to API Error Cases.


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