Validate Cart
curl --request POST \
--url https://api.khaime.com/api/v1/cart/validate \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"cart": [
{}
],
"currency": "<string>",
"delivery_details": {},
"coupons": [
{}
],
"user_country": "<string>"
}
'import requests
url = "https://api.khaime.com/api/v1/cart/validate"
payload = {
"cart": [{}],
"currency": "<string>",
"delivery_details": {},
"coupons": [{}],
"user_country": "<string>"
}
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({
cart: [{}],
currency: '<string>',
delivery_details: {},
coupons: [{}],
user_country: '<string>'
})
};
fetch('https://api.khaime.com/api/v1/cart/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/cart/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([
'cart' => [
[
]
],
'currency' => '<string>',
'delivery_details' => [
],
'coupons' => [
[
]
],
'user_country' => '<string>'
]),
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/cart/validate"
payload := strings.NewReader("{\n \"cart\": [\n {}\n ],\n \"currency\": \"<string>\",\n \"delivery_details\": {},\n \"coupons\": [\n {}\n ],\n \"user_country\": \"<string>\"\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/cart/validate")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"cart\": [\n {}\n ],\n \"currency\": \"<string>\",\n \"delivery_details\": {},\n \"coupons\": [\n {}\n ],\n \"user_country\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.khaime.com/api/v1/cart/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 \"cart\": [\n {}\n ],\n \"currency\": \"<string>\",\n \"delivery_details\": {},\n \"coupons\": [\n {}\n ],\n \"user_country\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Cart Details",
"data": {
"cart_unique_id": "bc59bc1f-e1b0-4ee5-a9cb-b966042ce38f",
"cart_items": [
{
"product_id": 12345,
"product_title": "Premium T-Shirt",
"quantity": 2,
"product_price": 2999,
"line_item_subtotal": 5998,
"line_item_discount_amount": 600,
"line_item_total_after_discounts": 5398,
"coupons_applied": ["SAVE10"]
}
],
"subtotal": 5998,
"discount_total": 600,
"shipping_fee": 599,
"tax": 432,
"tax_rate": 8,
"total": 5829,
"currency": "USD"
}
}
Commerce API
Validate Cart
Build and validate cart with shipping, taxes, and discounts
POST
/
cart
/
validate
Validate Cart
curl --request POST \
--url https://api.khaime.com/api/v1/cart/validate \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"cart": [
{}
],
"currency": "<string>",
"delivery_details": {},
"coupons": [
{}
],
"user_country": "<string>"
}
'import requests
url = "https://api.khaime.com/api/v1/cart/validate"
payload = {
"cart": [{}],
"currency": "<string>",
"delivery_details": {},
"coupons": [{}],
"user_country": "<string>"
}
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({
cart: [{}],
currency: '<string>',
delivery_details: {},
coupons: [{}],
user_country: '<string>'
})
};
fetch('https://api.khaime.com/api/v1/cart/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/cart/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([
'cart' => [
[
]
],
'currency' => '<string>',
'delivery_details' => [
],
'coupons' => [
[
]
],
'user_country' => '<string>'
]),
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/cart/validate"
payload := strings.NewReader("{\n \"cart\": [\n {}\n ],\n \"currency\": \"<string>\",\n \"delivery_details\": {},\n \"coupons\": [\n {}\n ],\n \"user_country\": \"<string>\"\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/cart/validate")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"cart\": [\n {}\n ],\n \"currency\": \"<string>\",\n \"delivery_details\": {},\n \"coupons\": [\n {}\n ],\n \"user_country\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.khaime.com/api/v1/cart/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 \"cart\": [\n {}\n ],\n \"currency\": \"<string>\",\n \"delivery_details\": {},\n \"coupons\": [\n {}\n ],\n \"user_country\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Cart Details",
"data": {
"cart_unique_id": "bc59bc1f-e1b0-4ee5-a9cb-b966042ce38f",
"cart_items": [
{
"product_id": 12345,
"product_title": "Premium T-Shirt",
"quantity": 2,
"product_price": 2999,
"line_item_subtotal": 5998,
"line_item_discount_amount": 600,
"line_item_total_after_discounts": 5398,
"coupons_applied": ["SAVE10"]
}
],
"subtotal": 5998,
"discount_total": 600,
"shipping_fee": 599,
"tax": 432,
"tax_rate": 8,
"total": 5829,
"currency": "USD"
}
}
Validate Cart
Validates cart items, calculates shipping, applies discounts, and returns acart_unique_id required for creating a payment intent.
This endpoint must be called before /payment/intent.
Request
string
required
Your API key
Body Parameters
array
required
Array of cart itemsEach item should have:
product_id(integer): Product IDquantity(integer): Quantityprice(integer): Price in smallest currency unit (cents)least_sub_variant_id(string): Variant ID if applicable
string
required
Currency code (e.g., “USD”)
object
Shipping address for physical products
first_name(string)last_name(string)email(string)phone(string)address(string)city(string)state(string)zip_code(string)country_code(string)
array
Array of coupon codes to apply
string
Customer’s country code for regional pricing
Response
{
"status": true,
"message": "Cart Details",
"data": {
"cart_unique_id": "bc59bc1f-e1b0-4ee5-a9cb-b966042ce38f",
"cart_items": [
{
"product_id": 12345,
"product_title": "Premium T-Shirt",
"quantity": 2,
"product_price": 2999,
"line_item_subtotal": 5998,
"line_item_discount_amount": 600,
"line_item_total_after_discounts": 5398,
"coupons_applied": ["SAVE10"]
}
],
"subtotal": 5998,
"discount_total": 600,
"shipping_fee": 599,
"tax": 432,
"tax_rate": 8,
"total": 5829,
"currency": "USD"
}
}
Example
curl -X POST "https://api.khaime.com/api/v1/cart/validate" \
-H "X-API-Key: pk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"cart": [
{
"product_id": 12345,
"quantity": 2,
"price": 2999,
"least_sub_variant_id": "var_001"
}
],
"currency": "USD",
"delivery_details": {
"first_name": "John",
"last_name": "Doe",
"email": "john@example.com",
"phone": "+1234567890",
"address": "123 Main St",
"city": "New York",
"state": "NY",
"zip_code": "10001",
"country_code": "US"
},
"coupons": ["SAVE10"]
}'
Notes
- The
cart_unique_idis valid for 24 hours - Save this ID and pass it to
/payment/intent - Prices are validated against the database to prevent tampering
- Currency conversion is applied automatically if multicurrency is enabled
⌘I
