curl --request POST \
--url https://api.fabric.inc/v3/price-engine/actions/evaluate-cart \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
--data '
{
"cartItems": [
{
"itemId": 1730902008,
"quantity": 15,
"position": 1,
"sku": "16B2GS8LD5FDS",
"productAttributes": [
{
"name": "gift wrapping (small)",
"value": "true",
"attributeId": "60c2a358eb2ec30008ae70a1",
"description": "Gift wrapping for a small package",
"mapping": "ITEM",
"type": "GIFT",
"price": 10,
"level": "order"
}
],
"priceListId": 108674,
"price": {
"sale": 1000.15,
"cost": 900.15,
"base": 2000.15,
"unitPriceWithoutDiscounts": 2000.15,
"lineTotalWithoutDiscounts": 2000.15,
"lineTotalWithDiscounts": 2000.15,
"type": "BASE"
},
"groups": [
"61d38e117162b7dba69c3d6d"
],
"attributes": {
"productFamily": "Laptop computers"
},
"shippingDetails": {
"shippingCost": 150.25,
"shippingMethodId": "dfsae-2d32113-32lpdd",
"shippingDiscount": 150.25,
"shippingMethodName": "Express Delivery"
},
"productCollections": [
"5e2cfb9b45570b000863c4b5"
]
}
],
"customer": {
"id": "5e2cfb9b45570b000864c4b5",
"segments": [
{
"name": "category",
"value": [
"GOLD",
"YELLOW"
]
},
{
"name": "ageGroup",
"value": [
"elderly"
]
}
]
},
"couponCodes": [
"SUPERCOUPON1"
],
"locale": "en-US"
}
'import requests
url = "https://api.fabric.inc/v3/price-engine/actions/evaluate-cart"
payload = {
"cartItems": [
{
"itemId": 1730902008,
"quantity": 15,
"position": 1,
"sku": "16B2GS8LD5FDS",
"productAttributes": [
{
"name": "gift wrapping (small)",
"value": "true",
"attributeId": "60c2a358eb2ec30008ae70a1",
"description": "Gift wrapping for a small package",
"mapping": "ITEM",
"type": "GIFT",
"price": 10,
"level": "order"
}
],
"priceListId": 108674,
"price": {
"sale": 1000.15,
"cost": 900.15,
"base": 2000.15,
"unitPriceWithoutDiscounts": 2000.15,
"lineTotalWithoutDiscounts": 2000.15,
"lineTotalWithDiscounts": 2000.15,
"type": "BASE"
},
"groups": ["61d38e117162b7dba69c3d6d"],
"attributes": { "productFamily": "Laptop computers" },
"shippingDetails": {
"shippingCost": 150.25,
"shippingMethodId": "dfsae-2d32113-32lpdd",
"shippingDiscount": 150.25,
"shippingMethodName": "Express Delivery"
},
"productCollections": ["5e2cfb9b45570b000863c4b5"]
}
],
"customer": {
"id": "5e2cfb9b45570b000864c4b5",
"segments": [
{
"name": "category",
"value": ["GOLD", "YELLOW"]
},
{
"name": "ageGroup",
"value": ["elderly"]
}
]
},
"couponCodes": ["SUPERCOUPON1"],
"locale": "en-US"
}
headers = {
"x-fabric-tenant-id": "<x-fabric-tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-fabric-tenant-id': '<x-fabric-tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
cartItems: [
{
itemId: 1730902008,
quantity: 15,
position: 1,
sku: '16B2GS8LD5FDS',
productAttributes: [
{
name: 'gift wrapping (small)',
value: 'true',
attributeId: '60c2a358eb2ec30008ae70a1',
description: 'Gift wrapping for a small package',
mapping: 'ITEM',
type: 'GIFT',
price: 10,
level: 'order'
}
],
priceListId: 108674,
price: {
sale: 1000.15,
cost: 900.15,
base: 2000.15,
unitPriceWithoutDiscounts: 2000.15,
lineTotalWithoutDiscounts: 2000.15,
lineTotalWithDiscounts: 2000.15,
type: 'BASE'
},
groups: ['61d38e117162b7dba69c3d6d'],
attributes: {productFamily: 'Laptop computers'},
shippingDetails: {
shippingCost: 150.25,
shippingMethodId: 'dfsae-2d32113-32lpdd',
shippingDiscount: 150.25,
shippingMethodName: 'Express Delivery'
},
productCollections: ['5e2cfb9b45570b000863c4b5']
}
],
customer: {
id: '5e2cfb9b45570b000864c4b5',
segments: [
{name: 'category', value: ['GOLD', 'YELLOW']},
{name: 'ageGroup', value: ['elderly']}
]
},
couponCodes: ['SUPERCOUPON1'],
locale: 'en-US'
})
};
fetch('https://api.fabric.inc/v3/price-engine/actions/evaluate-cart', 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.fabric.inc/v3/price-engine/actions/evaluate-cart",
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([
'cartItems' => [
[
'itemId' => 1730902008,
'quantity' => 15,
'position' => 1,
'sku' => '16B2GS8LD5FDS',
'productAttributes' => [
[
'name' => 'gift wrapping (small)',
'value' => 'true',
'attributeId' => '60c2a358eb2ec30008ae70a1',
'description' => 'Gift wrapping for a small package',
'mapping' => 'ITEM',
'type' => 'GIFT',
'price' => 10,
'level' => 'order'
]
],
'priceListId' => 108674,
'price' => [
'sale' => 1000.15,
'cost' => 900.15,
'base' => 2000.15,
'unitPriceWithoutDiscounts' => 2000.15,
'lineTotalWithoutDiscounts' => 2000.15,
'lineTotalWithDiscounts' => 2000.15,
'type' => 'BASE'
],
'groups' => [
'61d38e117162b7dba69c3d6d'
],
'attributes' => [
'productFamily' => 'Laptop computers'
],
'shippingDetails' => [
'shippingCost' => 150.25,
'shippingMethodId' => 'dfsae-2d32113-32lpdd',
'shippingDiscount' => 150.25,
'shippingMethodName' => 'Express Delivery'
],
'productCollections' => [
'5e2cfb9b45570b000863c4b5'
]
]
],
'customer' => [
'id' => '5e2cfb9b45570b000864c4b5',
'segments' => [
[
'name' => 'category',
'value' => [
'GOLD',
'YELLOW'
]
],
[
'name' => 'ageGroup',
'value' => [
'elderly'
]
]
]
],
'couponCodes' => [
'SUPERCOUPON1'
],
'locale' => 'en-US'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"x-fabric-tenant-id: <x-fabric-tenant-id>"
],
]);
$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.fabric.inc/v3/price-engine/actions/evaluate-cart"
payload := strings.NewReader("{\n \"cartItems\": [\n {\n \"itemId\": 1730902008,\n \"quantity\": 15,\n \"position\": 1,\n \"sku\": \"16B2GS8LD5FDS\",\n \"productAttributes\": [\n {\n \"name\": \"gift wrapping (small)\",\n \"value\": \"true\",\n \"attributeId\": \"60c2a358eb2ec30008ae70a1\",\n \"description\": \"Gift wrapping for a small package\",\n \"mapping\": \"ITEM\",\n \"type\": \"GIFT\",\n \"price\": 10,\n \"level\": \"order\"\n }\n ],\n \"priceListId\": 108674,\n \"price\": {\n \"sale\": 1000.15,\n \"cost\": 900.15,\n \"base\": 2000.15,\n \"unitPriceWithoutDiscounts\": 2000.15,\n \"lineTotalWithoutDiscounts\": 2000.15,\n \"lineTotalWithDiscounts\": 2000.15,\n \"type\": \"BASE\"\n },\n \"groups\": [\n \"61d38e117162b7dba69c3d6d\"\n ],\n \"attributes\": {\n \"productFamily\": \"Laptop computers\"\n },\n \"shippingDetails\": {\n \"shippingCost\": 150.25,\n \"shippingMethodId\": \"dfsae-2d32113-32lpdd\",\n \"shippingDiscount\": 150.25,\n \"shippingMethodName\": \"Express Delivery\"\n },\n \"productCollections\": [\n \"5e2cfb9b45570b000863c4b5\"\n ]\n }\n ],\n \"customer\": {\n \"id\": \"5e2cfb9b45570b000864c4b5\",\n \"segments\": [\n {\n \"name\": \"category\",\n \"value\": [\n \"GOLD\",\n \"YELLOW\"\n ]\n },\n {\n \"name\": \"ageGroup\",\n \"value\": [\n \"elderly\"\n ]\n }\n ]\n },\n \"couponCodes\": [\n \"SUPERCOUPON1\"\n ],\n \"locale\": \"en-US\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-fabric-tenant-id", "<x-fabric-tenant-id>")
req.Header.Add("Authorization", "Bearer <token>")
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.fabric.inc/v3/price-engine/actions/evaluate-cart")
.header("x-fabric-tenant-id", "<x-fabric-tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"cartItems\": [\n {\n \"itemId\": 1730902008,\n \"quantity\": 15,\n \"position\": 1,\n \"sku\": \"16B2GS8LD5FDS\",\n \"productAttributes\": [\n {\n \"name\": \"gift wrapping (small)\",\n \"value\": \"true\",\n \"attributeId\": \"60c2a358eb2ec30008ae70a1\",\n \"description\": \"Gift wrapping for a small package\",\n \"mapping\": \"ITEM\",\n \"type\": \"GIFT\",\n \"price\": 10,\n \"level\": \"order\"\n }\n ],\n \"priceListId\": 108674,\n \"price\": {\n \"sale\": 1000.15,\n \"cost\": 900.15,\n \"base\": 2000.15,\n \"unitPriceWithoutDiscounts\": 2000.15,\n \"lineTotalWithoutDiscounts\": 2000.15,\n \"lineTotalWithDiscounts\": 2000.15,\n \"type\": \"BASE\"\n },\n \"groups\": [\n \"61d38e117162b7dba69c3d6d\"\n ],\n \"attributes\": {\n \"productFamily\": \"Laptop computers\"\n },\n \"shippingDetails\": {\n \"shippingCost\": 150.25,\n \"shippingMethodId\": \"dfsae-2d32113-32lpdd\",\n \"shippingDiscount\": 150.25,\n \"shippingMethodName\": \"Express Delivery\"\n },\n \"productCollections\": [\n \"5e2cfb9b45570b000863c4b5\"\n ]\n }\n ],\n \"customer\": {\n \"id\": \"5e2cfb9b45570b000864c4b5\",\n \"segments\": [\n {\n \"name\": \"category\",\n \"value\": [\n \"GOLD\",\n \"YELLOW\"\n ]\n },\n {\n \"name\": \"ageGroup\",\n \"value\": [\n \"elderly\"\n ]\n }\n ]\n },\n \"couponCodes\": [\n \"SUPERCOUPON1\"\n ],\n \"locale\": \"en-US\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fabric.inc/v3/price-engine/actions/evaluate-cart")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-fabric-tenant-id"] = '<x-fabric-tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"cartItems\": [\n {\n \"itemId\": 1730902008,\n \"quantity\": 15,\n \"position\": 1,\n \"sku\": \"16B2GS8LD5FDS\",\n \"productAttributes\": [\n {\n \"name\": \"gift wrapping (small)\",\n \"value\": \"true\",\n \"attributeId\": \"60c2a358eb2ec30008ae70a1\",\n \"description\": \"Gift wrapping for a small package\",\n \"mapping\": \"ITEM\",\n \"type\": \"GIFT\",\n \"price\": 10,\n \"level\": \"order\"\n }\n ],\n \"priceListId\": 108674,\n \"price\": {\n \"sale\": 1000.15,\n \"cost\": 900.15,\n \"base\": 2000.15,\n \"unitPriceWithoutDiscounts\": 2000.15,\n \"lineTotalWithoutDiscounts\": 2000.15,\n \"lineTotalWithDiscounts\": 2000.15,\n \"type\": \"BASE\"\n },\n \"groups\": [\n \"61d38e117162b7dba69c3d6d\"\n ],\n \"attributes\": {\n \"productFamily\": \"Laptop computers\"\n },\n \"shippingDetails\": {\n \"shippingCost\": 150.25,\n \"shippingMethodId\": \"dfsae-2d32113-32lpdd\",\n \"shippingDiscount\": 150.25,\n \"shippingMethodName\": \"Express Delivery\"\n },\n \"productCollections\": [\n \"5e2cfb9b45570b000863c4b5\"\n ]\n }\n ],\n \"customer\": {\n \"id\": \"5e2cfb9b45570b000864c4b5\",\n \"segments\": [\n {\n \"name\": \"category\",\n \"value\": [\n \"GOLD\",\n \"YELLOW\"\n ]\n },\n {\n \"name\": \"ageGroup\",\n \"value\": [\n \"elderly\"\n ]\n }\n ]\n },\n \"couponCodes\": [\n \"SUPERCOUPON1\"\n ],\n \"locale\": \"en-US\"\n}"
response = http.request(request)
puts response.read_body{
"cartItems": [
{
"itemId": 1730902008,
"quantity": 15,
"position": 1,
"sku": "16B2GS8LD5FDS",
"productAttributes": [
{
"name": "gift wrapping (small)",
"value": "true",
"attributeId": "60c2a358eb2ec30008ae70a1",
"description": "Gift wrapping for a small package",
"mapping": "ITEM",
"type": "GIFT",
"price": 10,
"level": "order"
}
],
"priceListId": 108674,
"price": {
"sale": 1000.15,
"cost": 900.15,
"base": 2000.15,
"unitPriceWithoutDiscounts": 2000.15,
"lineTotalWithoutDiscounts": 2000.15,
"lineTotalWithDiscounts": 2000.15,
"type": "BASE"
},
"groups": [
"61d38e117162b7dba69c3d6d"
],
"attributes": {
"productFamily": "Laptop computers"
},
"shippingDetails": {
"shippingCost": 150.25,
"shippingMethodId": "dfsae-2d32113-32lpdd",
"shippingDiscount": 150.25,
"shippingMethodName": "Express Delivery"
},
"discounts": [
{
"amount": 100.15,
"quantity": 1,
"proratedAmount": 100.15,
"proratedQuantity": 1,
"application": 1,
"promotion": {
"id": "6197ec46e836ff000952d668",
"value": 2000.15,
"groupId": "61a6354d0d70e30009415f16",
"level": 1,
"isStackable": true,
"isAlwaysApplied": true,
"name": "20% OFF",
"type": "Coupon",
"discountType": "AMOUNT_OFF",
"stackingType": "STACKABLE"
}
}
],
"priceAttributes": {
"floor": 1000.15,
"cost": 900.15,
"clearance": 2000.15
},
"productCollections": [
"5e2cfb9b45570b000863c4b5"
]
}
],
"errors": [
"Parameter doesn't exist"
],
"appliedDiscounts": [
{
"promotionId": "6197ec46e836ff000952c665",
"promotionName": "Buy shoes get socks for free",
"couponCode": "SUPERCOUPON20",
"type": "COUPON",
"amount": 105.15,
"discountScope": "SKU",
"discountType": "AMOUNT_OFF",
"value": 10
}
],
"suggestedProducts": [
{
"promotionId": "6197ec46e836ff000952c665",
"promotionName": "Buy shoes get socks for free",
"itemId": 234343,
"itemIds": [
1120201,
1120202
],
"sku": "SHOE1234",
"skus": [
"SHOE-1",
"SHOE-2"
],
"eligiblePriceLists": [
10000
],
"quantity": 2,
"promotionQuantity": 10,
"isFree": true,
"discountType": "PERCENTAGE_OFF",
"amount": 105.15
}
],
"notAppliedCoupons": [
{
"couponCode": "SUPERCOUPON",
"promotionId": "624b5aa2a8fd12000965dfdc",
"message": "Invalid coupon"
}
],
"promotionMessages": [
{
"title": "Buy 2 get 1 free",
"message": "Offer valid at participating stores through September 5, 2023.",
"pages": [
"PDP"
],
"locales": [
"en-CA"
],
"type": "DISCOUNT",
"threshold": 2,
"promoId": "61df12345678900009b7091c"
}
]
}{
"type": "BAD_REQUEST",
"message": "Request isn't valid",
"errors": [
{
"type": "Bad request",
"message": "-1.0 isn't a valid shipping price. Value must be greater than or equal to 0."
}
]
}{
"type": "UNAUTHORIZED_ACCESS",
"message": "Unauthorized access"
}{
"type": "NOT_FOUND",
"message": "Item or SKU not found"
}{
"type": "INTERNAL_SERVER_ERROR",
"message": "Internal server error"
}Evaluate cart promotions
Evaluate cart’s total cost instantly, after applying all applicable promotions and discount coupons. Using this endpoint, submit a range of data that will be referenced against the conditions that are set earlier using the promotions, coupons or prices APIs. The response includes the details of the promotions and discounts applied. These promotions and discounts can be displayed on your website to help shoppers know that they’re getting their expected discounts.
curl --request POST \
--url https://api.fabric.inc/v3/price-engine/actions/evaluate-cart \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
--data '
{
"cartItems": [
{
"itemId": 1730902008,
"quantity": 15,
"position": 1,
"sku": "16B2GS8LD5FDS",
"productAttributes": [
{
"name": "gift wrapping (small)",
"value": "true",
"attributeId": "60c2a358eb2ec30008ae70a1",
"description": "Gift wrapping for a small package",
"mapping": "ITEM",
"type": "GIFT",
"price": 10,
"level": "order"
}
],
"priceListId": 108674,
"price": {
"sale": 1000.15,
"cost": 900.15,
"base": 2000.15,
"unitPriceWithoutDiscounts": 2000.15,
"lineTotalWithoutDiscounts": 2000.15,
"lineTotalWithDiscounts": 2000.15,
"type": "BASE"
},
"groups": [
"61d38e117162b7dba69c3d6d"
],
"attributes": {
"productFamily": "Laptop computers"
},
"shippingDetails": {
"shippingCost": 150.25,
"shippingMethodId": "dfsae-2d32113-32lpdd",
"shippingDiscount": 150.25,
"shippingMethodName": "Express Delivery"
},
"productCollections": [
"5e2cfb9b45570b000863c4b5"
]
}
],
"customer": {
"id": "5e2cfb9b45570b000864c4b5",
"segments": [
{
"name": "category",
"value": [
"GOLD",
"YELLOW"
]
},
{
"name": "ageGroup",
"value": [
"elderly"
]
}
]
},
"couponCodes": [
"SUPERCOUPON1"
],
"locale": "en-US"
}
'import requests
url = "https://api.fabric.inc/v3/price-engine/actions/evaluate-cart"
payload = {
"cartItems": [
{
"itemId": 1730902008,
"quantity": 15,
"position": 1,
"sku": "16B2GS8LD5FDS",
"productAttributes": [
{
"name": "gift wrapping (small)",
"value": "true",
"attributeId": "60c2a358eb2ec30008ae70a1",
"description": "Gift wrapping for a small package",
"mapping": "ITEM",
"type": "GIFT",
"price": 10,
"level": "order"
}
],
"priceListId": 108674,
"price": {
"sale": 1000.15,
"cost": 900.15,
"base": 2000.15,
"unitPriceWithoutDiscounts": 2000.15,
"lineTotalWithoutDiscounts": 2000.15,
"lineTotalWithDiscounts": 2000.15,
"type": "BASE"
},
"groups": ["61d38e117162b7dba69c3d6d"],
"attributes": { "productFamily": "Laptop computers" },
"shippingDetails": {
"shippingCost": 150.25,
"shippingMethodId": "dfsae-2d32113-32lpdd",
"shippingDiscount": 150.25,
"shippingMethodName": "Express Delivery"
},
"productCollections": ["5e2cfb9b45570b000863c4b5"]
}
],
"customer": {
"id": "5e2cfb9b45570b000864c4b5",
"segments": [
{
"name": "category",
"value": ["GOLD", "YELLOW"]
},
{
"name": "ageGroup",
"value": ["elderly"]
}
]
},
"couponCodes": ["SUPERCOUPON1"],
"locale": "en-US"
}
headers = {
"x-fabric-tenant-id": "<x-fabric-tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-fabric-tenant-id': '<x-fabric-tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
cartItems: [
{
itemId: 1730902008,
quantity: 15,
position: 1,
sku: '16B2GS8LD5FDS',
productAttributes: [
{
name: 'gift wrapping (small)',
value: 'true',
attributeId: '60c2a358eb2ec30008ae70a1',
description: 'Gift wrapping for a small package',
mapping: 'ITEM',
type: 'GIFT',
price: 10,
level: 'order'
}
],
priceListId: 108674,
price: {
sale: 1000.15,
cost: 900.15,
base: 2000.15,
unitPriceWithoutDiscounts: 2000.15,
lineTotalWithoutDiscounts: 2000.15,
lineTotalWithDiscounts: 2000.15,
type: 'BASE'
},
groups: ['61d38e117162b7dba69c3d6d'],
attributes: {productFamily: 'Laptop computers'},
shippingDetails: {
shippingCost: 150.25,
shippingMethodId: 'dfsae-2d32113-32lpdd',
shippingDiscount: 150.25,
shippingMethodName: 'Express Delivery'
},
productCollections: ['5e2cfb9b45570b000863c4b5']
}
],
customer: {
id: '5e2cfb9b45570b000864c4b5',
segments: [
{name: 'category', value: ['GOLD', 'YELLOW']},
{name: 'ageGroup', value: ['elderly']}
]
},
couponCodes: ['SUPERCOUPON1'],
locale: 'en-US'
})
};
fetch('https://api.fabric.inc/v3/price-engine/actions/evaluate-cart', 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.fabric.inc/v3/price-engine/actions/evaluate-cart",
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([
'cartItems' => [
[
'itemId' => 1730902008,
'quantity' => 15,
'position' => 1,
'sku' => '16B2GS8LD5FDS',
'productAttributes' => [
[
'name' => 'gift wrapping (small)',
'value' => 'true',
'attributeId' => '60c2a358eb2ec30008ae70a1',
'description' => 'Gift wrapping for a small package',
'mapping' => 'ITEM',
'type' => 'GIFT',
'price' => 10,
'level' => 'order'
]
],
'priceListId' => 108674,
'price' => [
'sale' => 1000.15,
'cost' => 900.15,
'base' => 2000.15,
'unitPriceWithoutDiscounts' => 2000.15,
'lineTotalWithoutDiscounts' => 2000.15,
'lineTotalWithDiscounts' => 2000.15,
'type' => 'BASE'
],
'groups' => [
'61d38e117162b7dba69c3d6d'
],
'attributes' => [
'productFamily' => 'Laptop computers'
],
'shippingDetails' => [
'shippingCost' => 150.25,
'shippingMethodId' => 'dfsae-2d32113-32lpdd',
'shippingDiscount' => 150.25,
'shippingMethodName' => 'Express Delivery'
],
'productCollections' => [
'5e2cfb9b45570b000863c4b5'
]
]
],
'customer' => [
'id' => '5e2cfb9b45570b000864c4b5',
'segments' => [
[
'name' => 'category',
'value' => [
'GOLD',
'YELLOW'
]
],
[
'name' => 'ageGroup',
'value' => [
'elderly'
]
]
]
],
'couponCodes' => [
'SUPERCOUPON1'
],
'locale' => 'en-US'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"x-fabric-tenant-id: <x-fabric-tenant-id>"
],
]);
$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.fabric.inc/v3/price-engine/actions/evaluate-cart"
payload := strings.NewReader("{\n \"cartItems\": [\n {\n \"itemId\": 1730902008,\n \"quantity\": 15,\n \"position\": 1,\n \"sku\": \"16B2GS8LD5FDS\",\n \"productAttributes\": [\n {\n \"name\": \"gift wrapping (small)\",\n \"value\": \"true\",\n \"attributeId\": \"60c2a358eb2ec30008ae70a1\",\n \"description\": \"Gift wrapping for a small package\",\n \"mapping\": \"ITEM\",\n \"type\": \"GIFT\",\n \"price\": 10,\n \"level\": \"order\"\n }\n ],\n \"priceListId\": 108674,\n \"price\": {\n \"sale\": 1000.15,\n \"cost\": 900.15,\n \"base\": 2000.15,\n \"unitPriceWithoutDiscounts\": 2000.15,\n \"lineTotalWithoutDiscounts\": 2000.15,\n \"lineTotalWithDiscounts\": 2000.15,\n \"type\": \"BASE\"\n },\n \"groups\": [\n \"61d38e117162b7dba69c3d6d\"\n ],\n \"attributes\": {\n \"productFamily\": \"Laptop computers\"\n },\n \"shippingDetails\": {\n \"shippingCost\": 150.25,\n \"shippingMethodId\": \"dfsae-2d32113-32lpdd\",\n \"shippingDiscount\": 150.25,\n \"shippingMethodName\": \"Express Delivery\"\n },\n \"productCollections\": [\n \"5e2cfb9b45570b000863c4b5\"\n ]\n }\n ],\n \"customer\": {\n \"id\": \"5e2cfb9b45570b000864c4b5\",\n \"segments\": [\n {\n \"name\": \"category\",\n \"value\": [\n \"GOLD\",\n \"YELLOW\"\n ]\n },\n {\n \"name\": \"ageGroup\",\n \"value\": [\n \"elderly\"\n ]\n }\n ]\n },\n \"couponCodes\": [\n \"SUPERCOUPON1\"\n ],\n \"locale\": \"en-US\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-fabric-tenant-id", "<x-fabric-tenant-id>")
req.Header.Add("Authorization", "Bearer <token>")
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.fabric.inc/v3/price-engine/actions/evaluate-cart")
.header("x-fabric-tenant-id", "<x-fabric-tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"cartItems\": [\n {\n \"itemId\": 1730902008,\n \"quantity\": 15,\n \"position\": 1,\n \"sku\": \"16B2GS8LD5FDS\",\n \"productAttributes\": [\n {\n \"name\": \"gift wrapping (small)\",\n \"value\": \"true\",\n \"attributeId\": \"60c2a358eb2ec30008ae70a1\",\n \"description\": \"Gift wrapping for a small package\",\n \"mapping\": \"ITEM\",\n \"type\": \"GIFT\",\n \"price\": 10,\n \"level\": \"order\"\n }\n ],\n \"priceListId\": 108674,\n \"price\": {\n \"sale\": 1000.15,\n \"cost\": 900.15,\n \"base\": 2000.15,\n \"unitPriceWithoutDiscounts\": 2000.15,\n \"lineTotalWithoutDiscounts\": 2000.15,\n \"lineTotalWithDiscounts\": 2000.15,\n \"type\": \"BASE\"\n },\n \"groups\": [\n \"61d38e117162b7dba69c3d6d\"\n ],\n \"attributes\": {\n \"productFamily\": \"Laptop computers\"\n },\n \"shippingDetails\": {\n \"shippingCost\": 150.25,\n \"shippingMethodId\": \"dfsae-2d32113-32lpdd\",\n \"shippingDiscount\": 150.25,\n \"shippingMethodName\": \"Express Delivery\"\n },\n \"productCollections\": [\n \"5e2cfb9b45570b000863c4b5\"\n ]\n }\n ],\n \"customer\": {\n \"id\": \"5e2cfb9b45570b000864c4b5\",\n \"segments\": [\n {\n \"name\": \"category\",\n \"value\": [\n \"GOLD\",\n \"YELLOW\"\n ]\n },\n {\n \"name\": \"ageGroup\",\n \"value\": [\n \"elderly\"\n ]\n }\n ]\n },\n \"couponCodes\": [\n \"SUPERCOUPON1\"\n ],\n \"locale\": \"en-US\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fabric.inc/v3/price-engine/actions/evaluate-cart")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-fabric-tenant-id"] = '<x-fabric-tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"cartItems\": [\n {\n \"itemId\": 1730902008,\n \"quantity\": 15,\n \"position\": 1,\n \"sku\": \"16B2GS8LD5FDS\",\n \"productAttributes\": [\n {\n \"name\": \"gift wrapping (small)\",\n \"value\": \"true\",\n \"attributeId\": \"60c2a358eb2ec30008ae70a1\",\n \"description\": \"Gift wrapping for a small package\",\n \"mapping\": \"ITEM\",\n \"type\": \"GIFT\",\n \"price\": 10,\n \"level\": \"order\"\n }\n ],\n \"priceListId\": 108674,\n \"price\": {\n \"sale\": 1000.15,\n \"cost\": 900.15,\n \"base\": 2000.15,\n \"unitPriceWithoutDiscounts\": 2000.15,\n \"lineTotalWithoutDiscounts\": 2000.15,\n \"lineTotalWithDiscounts\": 2000.15,\n \"type\": \"BASE\"\n },\n \"groups\": [\n \"61d38e117162b7dba69c3d6d\"\n ],\n \"attributes\": {\n \"productFamily\": \"Laptop computers\"\n },\n \"shippingDetails\": {\n \"shippingCost\": 150.25,\n \"shippingMethodId\": \"dfsae-2d32113-32lpdd\",\n \"shippingDiscount\": 150.25,\n \"shippingMethodName\": \"Express Delivery\"\n },\n \"productCollections\": [\n \"5e2cfb9b45570b000863c4b5\"\n ]\n }\n ],\n \"customer\": {\n \"id\": \"5e2cfb9b45570b000864c4b5\",\n \"segments\": [\n {\n \"name\": \"category\",\n \"value\": [\n \"GOLD\",\n \"YELLOW\"\n ]\n },\n {\n \"name\": \"ageGroup\",\n \"value\": [\n \"elderly\"\n ]\n }\n ]\n },\n \"couponCodes\": [\n \"SUPERCOUPON1\"\n ],\n \"locale\": \"en-US\"\n}"
response = http.request(request)
puts response.read_body{
"cartItems": [
{
"itemId": 1730902008,
"quantity": 15,
"position": 1,
"sku": "16B2GS8LD5FDS",
"productAttributes": [
{
"name": "gift wrapping (small)",
"value": "true",
"attributeId": "60c2a358eb2ec30008ae70a1",
"description": "Gift wrapping for a small package",
"mapping": "ITEM",
"type": "GIFT",
"price": 10,
"level": "order"
}
],
"priceListId": 108674,
"price": {
"sale": 1000.15,
"cost": 900.15,
"base": 2000.15,
"unitPriceWithoutDiscounts": 2000.15,
"lineTotalWithoutDiscounts": 2000.15,
"lineTotalWithDiscounts": 2000.15,
"type": "BASE"
},
"groups": [
"61d38e117162b7dba69c3d6d"
],
"attributes": {
"productFamily": "Laptop computers"
},
"shippingDetails": {
"shippingCost": 150.25,
"shippingMethodId": "dfsae-2d32113-32lpdd",
"shippingDiscount": 150.25,
"shippingMethodName": "Express Delivery"
},
"discounts": [
{
"amount": 100.15,
"quantity": 1,
"proratedAmount": 100.15,
"proratedQuantity": 1,
"application": 1,
"promotion": {
"id": "6197ec46e836ff000952d668",
"value": 2000.15,
"groupId": "61a6354d0d70e30009415f16",
"level": 1,
"isStackable": true,
"isAlwaysApplied": true,
"name": "20% OFF",
"type": "Coupon",
"discountType": "AMOUNT_OFF",
"stackingType": "STACKABLE"
}
}
],
"priceAttributes": {
"floor": 1000.15,
"cost": 900.15,
"clearance": 2000.15
},
"productCollections": [
"5e2cfb9b45570b000863c4b5"
]
}
],
"errors": [
"Parameter doesn't exist"
],
"appliedDiscounts": [
{
"promotionId": "6197ec46e836ff000952c665",
"promotionName": "Buy shoes get socks for free",
"couponCode": "SUPERCOUPON20",
"type": "COUPON",
"amount": 105.15,
"discountScope": "SKU",
"discountType": "AMOUNT_OFF",
"value": 10
}
],
"suggestedProducts": [
{
"promotionId": "6197ec46e836ff000952c665",
"promotionName": "Buy shoes get socks for free",
"itemId": 234343,
"itemIds": [
1120201,
1120202
],
"sku": "SHOE1234",
"skus": [
"SHOE-1",
"SHOE-2"
],
"eligiblePriceLists": [
10000
],
"quantity": 2,
"promotionQuantity": 10,
"isFree": true,
"discountType": "PERCENTAGE_OFF",
"amount": 105.15
}
],
"notAppliedCoupons": [
{
"couponCode": "SUPERCOUPON",
"promotionId": "624b5aa2a8fd12000965dfdc",
"message": "Invalid coupon"
}
],
"promotionMessages": [
{
"title": "Buy 2 get 1 free",
"message": "Offer valid at participating stores through September 5, 2023.",
"pages": [
"PDP"
],
"locales": [
"en-CA"
],
"type": "DISCOUNT",
"threshold": 2,
"promoId": "61df12345678900009b7091c"
}
]
}{
"type": "BAD_REQUEST",
"message": "Request isn't valid",
"errors": [
{
"type": "Bad request",
"message": "-1.0 isn't a valid shipping price. Value must be greater than or equal to 0."
}
]
}{
"type": "UNAUTHORIZED_ACCESS",
"message": "Unauthorized access"
}{
"type": "NOT_FOUND",
"message": "Item or SKU not found"
}{
"type": "INTERNAL_SERVER_ERROR",
"message": "Internal server error"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
A header used by fabric to identify the tenant making the request. You must include tenant id in the authentication header for an API request to access any of fabric’s endpoints. You can retrieve the tenant id , which is also called account id, from Copilot. This header is required.
24The Date and time, in ISO 8601 format, for which the evaluation should be done. The prices and promotions that are active on this date will be considered for evaluation.
"2022-09-06T14:07:17.000Z"
A unique request ID.
"263e731c-45c8-11ed-b878-0242ac120002"
x-fabric-channel-id identifies the sales channel where the API request is being made; primarily for multichannel use cases. The channel ids are 12 corresponding to US and 13 corresponding to Canada. The default channel id is 12. This field is required.
"12"
Body
A sample cart evaluation request.
The details of items in the cart.
Show child attributes
Show child attributes
Customer details
Show child attributes
Show child attributes
Promotion codes to be applied
Promotion code
The language code, which is a combination of language in ISO 639 format and country in ISO 3166 format. The default value is en-US.
"en-US"
Response
OK
The response of the evaluation request of the cart promotion.
The list of items in the cart.
Show child attributes
Show child attributes
The error details.
The list of errors.
["Parameter doesn't exist"]
The details of the discounts applied to the cart.
Show child attributes
Show child attributes
[
{
"promotionId": "6197ec46e836ff000952c665",
"promotionName": "Buy shoes get socks for free",
"couponCode": "SUPERCOUPON20",
"type": "COUPON",
"amount": 105.15,
"discountScope": "SKU",
"discountType": "AMOUNT_OFF",
"value": 10
}
]
Suggested free products
Show child attributes
Show child attributes
[
{
"promotionId": "6197ec46e836ff000952c665",
"promotionName": "Buy shoes get socks for free",
"itemId": 234343,
"itemIds": [1120201, 1120202],
"sku": "SHOE1234",
"skus": ["SHOE-1", "SHOE-2"],
"eligiblePriceLists": [10000],
"quantity": 2,
"promotionQuantity": 10,
"isFree": true,
"discountType": "PERCENTAGE_OFF",
"amount": 105.15
}
]
Rejected coupons
Show child attributes
Show child attributes
[
{
"couponCode": "SUPERCOUPON",
"promotionId": "624b5aa2a8fd12000965dfdc",
"message": "Invalid coupon"
}
]
The promotion message that is displayed to the customer.
Show child attributes
Show child attributes
Was this page helpful?
