Validate Coupon
curl --request POST \
--url https://api.khaime.com/api/v1/coupon/validate \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"coupon_code": "<string>",
"product_id": 123
}
'import requests
url = "https://api.khaime.com/api/v1/coupon/validate"
payload = {
"coupon_code": "<string>",
"product_id": 123
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({coupon_code: '<string>', product_id: 123})
};
fetch('https://api.khaime.com/api/v1/coupon/validate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.khaime.com/api/v1/coupon/validate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'coupon_code' => '<string>',
'product_id' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.khaime.com/api/v1/coupon/validate"
payload := strings.NewReader("{\n \"coupon_code\": \"<string>\",\n \"product_id\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.khaime.com/api/v1/coupon/validate")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"coupon_code\": \"<string>\",\n \"product_id\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.khaime.com/api/v1/coupon/validate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"coupon_code\": \"<string>\",\n \"product_id\": 123\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Coupon is valid",
"data": {
"coupon_code": "SAVE20",
"discount_type": "percentage",
"discount_value": 20,
"is_valid": true,
"applicable_products": [12345, 12346],
"min_order_amount": 5000,
"max_uses": 100,
"current_uses": 45,
"expires_at": "2024-12-31T23:59:59Z"
}
}
Commerce API
Validate Coupon
Check if a coupon code is valid
POST
/
coupon
/
validate
Validate Coupon
curl --request POST \
--url https://api.khaime.com/api/v1/coupon/validate \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"coupon_code": "<string>",
"product_id": 123
}
'import requests
url = "https://api.khaime.com/api/v1/coupon/validate"
payload = {
"coupon_code": "<string>",
"product_id": 123
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({coupon_code: '<string>', product_id: 123})
};
fetch('https://api.khaime.com/api/v1/coupon/validate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.khaime.com/api/v1/coupon/validate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'coupon_code' => '<string>',
'product_id' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.khaime.com/api/v1/coupon/validate"
payload := strings.NewReader("{\n \"coupon_code\": \"<string>\",\n \"product_id\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.khaime.com/api/v1/coupon/validate")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"coupon_code\": \"<string>\",\n \"product_id\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.khaime.com/api/v1/coupon/validate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"coupon_code\": \"<string>\",\n \"product_id\": 123\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Coupon is valid",
"data": {
"coupon_code": "SAVE20",
"discount_type": "percentage",
"discount_value": 20,
"is_valid": true,
"applicable_products": [12345, 12346],
"min_order_amount": 5000,
"max_uses": 100,
"current_uses": 45,
"expires_at": "2024-12-31T23:59:59Z"
}
}
Validate Coupon
Validates a coupon code and returns the discount details.Request
string
required
Your API key
Body Parameters
string
required
The coupon code to validate
integer
Product ID to check coupon applicability
Response
{
"status": true,
"message": "Coupon is valid",
"data": {
"coupon_code": "SAVE20",
"discount_type": "percentage",
"discount_value": 20,
"is_valid": true,
"applicable_products": [12345, 12346],
"min_order_amount": 5000,
"max_uses": 100,
"current_uses": 45,
"expires_at": "2024-12-31T23:59:59Z"
}
}
Errors
| Error Code | Description |
|---|---|
COUPON_NOT_FOUND | Coupon code doesn’t exist |
COUPON_EXPIRED | Coupon has expired |
COUPON_USAGE_LIMIT_REACHED | Coupon has been used too many times |
Example
curl -X POST "https://api.khaime.com/api/v1/coupon/validate" \
-H "X-API-Key: pk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"coupon_code": "SAVE20",
"product_id": 12345
}'
⌘I
