API: Code Validation
Whenever a user attempts to apply a code to the basket, the Validation API is used to determine the validity of the code that has been entered. It also receives the response that allows the merchant to know which offer to apply to the purchase.
Endpoint:
https://api.uniqodo.com/validate/API_KEY/PROMO_CODE/MERCHANT
Example API call:
GET
https://api.uniqodo.com/validate/64a287ae534cf1bd58f45f3e23de9d433caec669/AB12E3GH/1?
email=example@email.com&pos=web&locale=en_GB&baseValidationParam=productId&itemSeparator=;&productId=123ABC;JS123EF&price=50.00;95.99&quantity=1;2&basketTotal=123.45&customerType=new
POST
POST https://api.uniqodo.com/validate/64a287ae534cf1bd58f45f3e23de9d433caec669/AB12E3GH/1 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: api.uniqodo.com
Content-Length: 67
Body: email=example@email.com&pos=web&locale=en_GB&baseValidationParam=productId&itemSeparator=;&productId=123ABC;JS123EF&price=50.00;95.99&quantity=1;2&basketTotal=123.45&customerType=new
Parameters:
Parameter | Description | Format | Required |
API_KEY | The API key assigned to the merchant. Found on the Settings page at https://your.uniqodo.com | 64a287ae534cf1bd58f45f3e23de9d433caec669 | Yes |
PROMO_CODE | The code provided by the shopper. | AB12E3GH | Yes |
merchant | The ID of the merchant making the API call to validate a code. | 1 | Yes |
The email for the shopper making the purchase. This is only required if the code being redeemed is a secure code type. | example@email.com | No | |
locale | The language of the site where code validation is taking place. This is useful for error message translations in customer's selected language. | Language tags with underscore: en_GB or the ISO 639-1 alpha-2 code such as en, fr, ... | Yes, if you have a multi-lingual platform |
pos | The point of sale or brand where the promotion is being applied. | web, mobile or brand name. | No |
Validation Lock
The validation lock feature allows you to lock a valid code to a customer's checkout session ensure the same unique code cannot be used by another customer in a different session. The default lock period is 1 hour during which only one customer can use the code in checkout. The lock period is also configurable in the settings area of your Uniqodo account.
To ensure that the right customer can test their code multiple times (i.e. add the code, remove and add the code back again) you must;
- keep the validation key in the customer's session and update it each time a code is successfully validated and
- send the key in the
pn
parameter for subsequent code validation requests in the same customer session e.g.pn=VALIDATION_KEY
. See the example below.
POST https://api.uniqodo.com/validate/64a287ae534cf1bd58f45f3e23de9d433caec669/AB12E3GH/1 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: api.uniqodo.com
Content-Length: 67
Body: email=example@email.com&pos=web&locale=en_GB&pn=525c12eb631b60421fb3e64c9bf16
Validation Rule Parameters
The Uniqodo validation rule engine allows rules and further restrictions to be applied to a promotional code based on parameters and values passed to the API. Restrictions could be arranged around the customer's basket data, for example, as well as any other accessible data item relating to the purchase.
A rule is created against these parameters when the promotion is set up on the Uniqodo platform. When a code validation API request is made, the validation rule parameters and values are checked against the rule criteria.
Parameter | Description | Required |
baseValidationParam | The name of the main data item or a parameter containing the products in the basket (e.g. productId). For instance, if the products being bought are stored in a parameter named 'productId', then the baseValidationParam parameter should contain 'productId' as its value. This parameter should uniquely identify the individual product in the basket. The parameter passed as a value here ('productId' in this example) must also be passed as a separate parameter to the API.Please see example parameters below. | Yes |
itemSeparator | Contains the character used to separate multiple values. If there are multiple items in the basket, product information are often concatenated using a special character. For example, if product codes are separated by a semicolon such as productId=123ABC;JS123EF, then the itemSeparator parameter should be ; ... &itemSeparator=; | Yes |
valueSeparator | When there are many items in a single value (similar to a list) you can delimit these values further using a web-safe character such as a comma For example, a product has one single ID in the productId parameter but a product can have multiple related products in the
This shows that product whilst product | Yes, if a parameter contains a list |
Example
baseValidationParam=productId&itemSeparator=;&productId=P2322;P2763&price=100.00;50.50&basketTotal=90.50&customerType=new
All other parameters used in the rule must also be supplied. If you have the rule below set up for a promotion,
(basketTotal > 700 AND customerType == 'new')
then both basketTotal and customerType must be supplied as additional request parameters.
Naming Parameters
All parameter names must;
- be alphanumeric but not start with a number
- not contain special characters except underscore (_) and hyphen (-)
- not contain spaces
Response
A successful API call will contain response data under the 'data' key.
{
"data": {
"val_key": "525c12eb631b60421fb3e64c9bf161a346a3039e68ec11b86ff11111a65b2691",
"offer_id": 37,
"merchant_id": 1,
"distributor_id": 1,
"locked_until": null,
"code": "SAVE25",
"validated_at": "2018-11-26T20:55:20+0000",
"discount_amount": 25,
"discount_type": "percentage",
"discount_breakdown": [],
"code_url": "http://www.example.com/",
"promotion_specific_error": null,
"tags" : ["PROMOTION_TAG_1", "PROMOTION_TAG_2" ...]
},
"errors": [],
}
Item | Description | Example |
val_key | A unique key for the code validation record. This key MUST be sent along when the redemption API is called to redeem the code. | 525c12eb631b60421fb3e64c9bf161a346a3039e68ec11b86ff11111a65b269 |
offer_id | The ID of the offer associated with this code. | 1256 |
merchant_id | The ID of the merchant validating the code. | 1 |
distributor_id | The ID of the distributor that issued the code to the shopper. | 2 |
locked_until | The validation lock is an optional advanced setting on a promotion. Where this setting applies, a code cannot be used until the current lock has expired. The lock is set after every successful validation of the same unique code. The lock expiry that indicates when the code is available for use again will be returned in the locked_until key. | 2018-05-29T10:39:17+0000 |
code | The trigger/master code that is used to apply the promotion in your eCommerce platform. The code should be applied to the customer's basket. | SUMMER10 |
discount_amount | The amount of discount associated with the promotion. This value must be used in conjunction with the discount_type key. Where product level discounts apply, the discount information contained within the discount_breakdown key should take precedence over the top level discount_amount and discount_type keys. Please see the Product Level Discounts section for details. | 10 |
discount_type | Whether the discount amount represents a percentage or a set monetary value. The discount_type is "percentage" for a percentage type discount e.g. 15% or "setamount" for a set value discount e.g. £10 | percentage |
validated_at | The date and time that the code validation occurred. | 2015-05-29T10:39:17+0000 |
code_url | The URL set against the promotion when it was set up in the Uniqodo platform. | https://example.com |
promotion_specific_error | A general error message for a promotion set when the promotion was set up. | This code can not be used unless you spend over £50 |
tags | An array of all tags attached to the promotion. An empty array is returned when no tags are attached to the promotion. | ["IN_STORE", "FASHION" ] |
Product Level Discounts:
The Uniqodo variable discounts functionality allows you to set different discount amounts depending on the items in the customer's basket. The customer only gets issued one single-use unique code which is then used to apply the different levels of discounts to the individual qualifying products in their basket. The applicable rule can be based on product ID, category or any other basket item data like stock levels.
For instance, using the same coupon code, you could offer a 5% discount on TV and 10% discount on mobile phones. In this example, if the customer has a TV and a microwave in their basket then the 5% discount will only apply to the price of the TV as no discount is offered on microwaves. If their basket contains a TV and a mobile phone then 5% will be taken off the price of the TV and 10% off the mobile phone as both are qualifying products.
When product level discounts are enforced, the code validation response will include the breakdown of all discounts to be applied under the "discount_breakdown" key. Please see the example below.
{
"data": {
...
"code": "EXAMPLE2OFF",
"validated_at": "2018-11-26T20:55:20+0000",
"discount_amount": 2,
"discount_type": "percentage",
"discount_breakdown": [
{
"product_id" : "SKU928289",
"price": 550.50,
"discount_amount": 5,
"discount_type": "percentage",
"discount_value": 27.53,
"quantity": 1,
},
{
"product_id": "SKU002751",
"price": 250.00,
"discount_amount": 10,
"discount_type": "percentage",
"discount_value": 25.00,
"quantity": 2,
}
...
],
"total_discount_value" : 52.53
"code_url": "http://www.example.com/",
"promotion_specific_error": null
},
"errors": []
}
Example product level discount rule:
Rules are added when the promotions are set up on the Uniqodo platform.
POST /validate/***********API_KEY_HERE***********/UQDC38BP/1 HTTP/1.1
HOST: api.uniqodo.com
content-type: application/x-www-form-urlencoded
content-length: 110
productId=P111;P7777;P222&quantity=1;2;3&price=29.99;50.50;80.50&itemSeparator=;&baseValidationParam=productId
{
"data": {
"id": 6310251,
"offer_id": 4851,
"merchant_id": 126,
"distributor_id": 1,
"locked_until": null,
"code": "PROD-LEVEL-DISCOUNT",
"validated_at": "2019-02-22T09:00:35+0000",
"discount_amount": null,
"discount_type": null,
"total_discount_value": 31.095,
"trigger_code": "PROD-LEVEL-DISCOUNT",
"code_url": "http:\/\/www.railcards.co.uk",
"promotion_specific_error": null,
"tags": [],
"discount_breakdown": [{
"product_id": "p111",
"price": 29.99,
"quantity": 1,
"discount_amount": 0.5,
"discount_type": "percentage",
"discount_value": 14.995
}, {
"product_id": "p222",
"price": 80.5,
"quantity": 3,
"discount_amount": 0.2,
"discount_type": "percentage",
"discount_value": 16.1
}]
},
"errors": [],
"result": "success"
}
Discount Breakdown Data
Item | Description | Example |
product_id | The unique identifier for the product. | TV04158844 |
price | The pre-discount price of the item. | 75.99 |
discount_amount | The numeric amount of discount to be applied to the product. This value must be used in conjunction with the discount_type key. | 15.5 |
discount_type | Whether the discount amount represents a percentage or a set monetary value. The discount_type is "percentage" for a percentage type discount e.g. 15% or "setamount" for a set value discount e.g. £10 | 'percentage' or 'setamount' |
discount_value | The resulting value from the discount calculation that should be deducted from the product price. For example, if the discount_amount is 10, the discount_type is percentage and the product price is 200 then the resulting discount value would be 20. | 20.00 |
total_discount_value | The sum of all discount values from the discount breakdown elements. | 150.59 |
Errors (All Merchant APIs):
Error format:
{
"data": {},
"errors": [{
"code": 202,
"message": "This code has expired and can no longer be used.",
"promotion_specific_error": null
}]
}
Codes using validation rules may contain multiple errors depending on the number of violations.
{
"data": {},
"errors": [
{
"message": "This code is only valid for newly registered customers.",
"code": 501
},
{
"message": "Your total basket value must be £500 or more to qualify for this discount.",
"code": 501
}
...
]
}
Error code | Message | Reason |
101 | Invalid API key supplied | The API key entered is not a valid API key |
201 | Code already redeemed | The code entered has already been redeemed. |
202 | Offer for this code has expired | The offer that the code is associated with has expired. |
204 | Code not recognised | The code entered is a master (trigger) code or not a code issued by or known to Uniqodo. This error type comes with an additional key 'reference' that indicates whether or not the promo code is a master code. { When the error code is 204 and the 'reference' key does NOT contain any value, it means the code is a master code should not be allowed. If the reference key has a value, which would be the promo code being validated, it means the promo code does not exist on Uniqodo and you can continue with verifying the promo code with your own promo code system. |
205 | Code is not valid with the supplied email address | The code is not valid with the supplied email address. |
206 | No more codes available | The limit for how many codes can be redeemed has been reached. |
208 | User email address required for secure codes | An email address needs to be entered alongside the supplied code. |
209 | This code is currently being validated | The code has already been validated within the validation lock period set for the merchant (See note below) |
210 | This code has been used %s times and can't be used further. | Multi-use limit of a unique code has been reached. %s is a placeholder for a number |
400 | The request could not be completed- check that parameters are correct | One of the required parameters is missing or the URL is badly formed |
501 | Validation Rule Error. The Message depends on the broken rule. Multiple errors may be returned. | A validation rule condition has not been met |