v1

latestOpenAPI 3.0.1MIT2026-07-263151,3912.3 MB
Client-side

Validate Voucher (client-side)

❗️ Deprecated

This endpoint represents the deprecated version of the API responsible for voucher validation, and we do not recommend using it. The new Stackable Discounts API introduces additional features and improvements while maintaining backward compatibility, including applying a combination of coupon codes and promotion tiers. Developers are encouraged to migrate to the latest version to take advantage of the latest enhancements and bug fixes. No updates will be provided to the deprecated endpoint.

To verify a voucher code given by customer, you can use this method. It is designed for client side integration which means that is accessible only through public keys. This method is designed to be run directly either in web browsers or mobile apps.

❗️ Specifying gift credits and loyalty points

This endpoint does not support specifying the specific amount of gift credits to apply to an order nor the specific amount of loyalty points to an order. It calculates the amount that is available on the card and applies as much credits or points as possible to cover the total amount.

Set customer identity (optional)

Voucherify can help you track anonymous customers. Once you integrate Voucherify into your web app and call the validate method, Voucherify will return a tracking ID and the script will store it in a cookie. Each subsequent validate call will use the same tracking ID.

Voucherify tracks a user using a tracking ID to see if the user who is validating vouchers is the same as the one who consuming them. Voucherify does this by setting up an identity for the user. A tracking_id will be generated on the server side, unless you specify your own tracking_id. In both cases, you will receive the tracking_id in the validation response.

The returned tracking_id field should be used as the customer source_id in subsequent redemption requests. Moreover, the tracking_id returned from Validation API is encoded. Voucherify will recognize both values for identifying customer - the one before encryption sent as a query parameter to the GET v1/validate request, and the version encrypted and returned as part of the validation request.

Sample workflow

Customer tracking workflow in a nutshell:

Client-side:

  • A customer visits your website.
  • A customer validates a voucher code. That triggers a validate request to be sent to Voucherify. In the request, you pass the tracking_id or customer.source_id. As a result, the API call to this endpoint returns an encoded tracking_id.

Backend:

  • Once the customer finishes the checkout process, your website passes the tracking_id to your backend during a redemption call. The tracking_id is sent as a value assigned to the property source_id in a customer object.
  • A customer object is created and within the redemption response, you get a customer id.
  • You can use the customer id or the customer source_id to fetch or modify the customer details.

A customer is created (upserted) automatically with a redemption call. Alternatively, you can create a new profile by creating a customer via a dedicated API method. Take a look at the customer object to understand the entity's structure.

📘 Customer identifier

The source id of the customer may either be an already hashed version of the tracking_id, which you received in a response from a validation request or a custom ID you predefined (i.e. an email address). Nevertheless, we recommend using identifiers delivered by Voucherify API.

Examples with Query Parameters

Query ParametersExample URL
Shortcut - customer query param instead of customer[source_id]https://api.voucherify.io/client/v1/validate?code=sKKFCKLZ&amount=10100&customer=customer_id
Pass customer's and redemption's context metadata in query parametershttps://api.voucherify.io/client/v1/validate?code=sKKFCKLZ&amount=10100&customer=sure_he_is_new&metadata[shop]=1&customer[metadata][propsy]=2&metadata[test]=true
Use tracking_id instead of source_idhttps://api.voucherify.io/client/v1/validate?code=IKU-mvS-JOG&amount=10100&tracking_id=sure_he_is_new_5&metadata[shop]=1&metadata[test]=true

Reasons why a validation might fail

Voucher validation might fail because of one of these reasons:

  • voucher not found - voucher doesn't exist or was deleted
  • voucher expired - voucher is out of [start date - expiration date] timeframe
  • voucher is disabled - learn more about disabled vouchers
  • customer does not match segment rules - learn more about customer tracking
  • order does not match validation rules - learn more about validation rules
get/client/v1/validate

Query parameters

codestring
Example:2CpRCE2c

A code that identifies the voucher.

tracking_idstring

A tracking identifier of a user that validated the voucher. This identifier is generated during voucher validation based on your internal ID (e.g., email, database ID) during the first request. This is a hashed customer source ID. If the request is performed for the first time, pass the internal ID to track the customer. Although not all information is required, the extra information helps prevent fraud.

amountstring

A positive integer in the smallest currency unit (e.g. 100 cents for $1.00) representing the total amount of the order. This is the sum of the order items' amounts.

session_keystring
Example:ssn_yQGMTeKBSw8OOuFPwlBEjzGy8d8VA9Ts

The session unique ID assigned by Voucherify or your own unique session ID. Sending an existing ID will result in overwriting an existing session. If no session key is provided, then a new ID will be generated.

session_ttlinteger

Value for the period of time that the session is active. Units for this parameter are defined by the session_ttl_unit parameter.

session_ttl_unit'HOURS' | 'DAYS' | 'MINUTES' | 'SECONDS' | 'MILLISECONDS' | 'MICROSECONDS' | 'NANOSECONDS'

Defines the type of unit in which the session time is counted.

metadataobject

Metadata key value pairs.

source_idstring

The merchant's product/SKU ID (if it is different from the Voucherify product/SKU ID). It is useful in the integration between multiple systems. It can be an ID from an eCommerce site, a database, or a third-party service.

related_objectstring

Used along with the source_id property, can be set to either sku or product.

product_idstring

Unique identifier of the product. It is assigned by Voucherify.

sku_idstring

Unique identifier of the SKU. It is assigned by Voucherify.

quantitystring

The quantity of the particular item in the cart.

pricestring

The unit price of the item.

amountstring

The total amount of the order item (price * quantity).

Array of order items.

[
  {
    "product_id": "prod_0a7e62db1fca8322a2",
    "sku_id": "sku_0a41e31c7b41c28358"
  }
]
session_typestring

The session is required to establish a session between multiple parallel validation and redemption requests. This parameter is required to establish a new session. The session locks the redemption quantity by 1 and additionally the redemption gift credits specified within the request for a gift card and the loyalty points for a loyalty card.

OR
string

Unique customer ID assigned by Voucherify, i.e. cust_eWgXlBBiY6THFRJwX45Iakv4.

Customer details.

{
  "source_id": "name.lastname@email.com"
}
metadataobject

The metadata object stores all custom attributes assigned to the order. A set of key/value pairs that are attached to an order object. Stores additional information about the order in a structured format.

Order details.

Headers

originstring hostname required

Indicates the origin (scheme, hostname, and port).

Response

Returns information whether the voucher is valid in the context of the parameter values provided in the query parameters. Moreover, it returns a hashed source identifier which can be used as tracking ID in future calls. If a validation session is established, then the session details will be returned as well. Read more on validation sessions.

OR

Example response

{
  "applicable_to": {
    "data": [
      {
        "id": "pc_4ndRXAsTOzwSdHcQcxf489uU"
      }
    ]
  },
  "inapplicable_to": {
    "data": [
      {
        "id": "pc_4ndRXAsTOzwSdHcQcxf489uU"
      }
    ]
  },
  "order": {
    "id": "ord_OLWs41pBk7VFn6ZTyX9U6keh",
    "created_at": "2022-10-06T11:40:48.705Z",
    "updated_at": "2022-10-06T11:47:20.760Z",
    "items": [
      {
        "product_id": "prod_5h0wc453_1",
        "sku_id": "sku_prod_5h0wc453_1_1",
        "product": {
          "id": "prod_5h0wc453_1",
          "source_id": "illy-arabica",
          "name": "Brewing System"
        },
        "sku": {
          "id": "sku_prod_5h0wc453_1_1",
          "source_id": "illy-arabica-250g"
        }
      }
    ],
    "customer": {
      "id": "cust_7iUa6ICKyU6gH40dBU25kQU1"
    },
    "referrer": {
      "id": "cust_7iUa6ICKyU6gH40dBU25kQU1"
    },
    "customer_id": "cust_7iUa6ICKyU6gH40dBU25kQU1",
    "referrer_id": "cust_nM4jqPiaXUvQdVSA6vTRUnix"
  },
  "discount": {
    "unit_type": "prod_0a9f9ab4ab019a42d5"
  },
  "start_date": "2022-10-04T00:00:00.000Z",
  "expiration_date": "2022-10-31T00:00:00.000Z",
  "campaign_id": "camp_W8DJVd8J0btqXT6FBwn7BSkC",
  "session": {
    "key": "ssn_yQGMTeKBSw8OOuFPwlBEjzGy8d8VA9Ts"
  }
}