Replace promotions - Fabric
Replace promotions
cURL
curl --request PUT \
--url https://api.fabric.inc/v3/carts/{cartId}/promotions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
--data '
{
"promotions": [\
{\
"id": "542ba80a69b8",\
"title": "15 Percent All Products",\
"code": "15_PERCENT",\
"type": "PERCENTAGE",\
"value": 15,\
"attributes": {\
"source": "cart"\
},\
"lineItems": [\
{\
"id": "bb44db95-6fbd-4eed-a1ed-4d99bc91250f",\
"amount": 15,\
"quantity": 3,\
"proration": {\
"spread": [\
{\
"amount": 5,\
"quantity": 3\
}\
]\
}\
}\
],\
"fulfillments": [\
{\
"id": "bb44db95-6fbd-4eed-a1ed-4d99bc91250f",\
"amount": 10\
}\
]\
}\
]
}'
Python
import requests
url = "https://api.fabric.inc/v3/carts/{cartId}/promotions"
payload = { "promotions": [\
{\
"id": "542ba80a69b8",\
"title": "15 Percent All Products",\
"code": "15_PERCENT",\
"type": "PERCENTAGE",\
"value": 15,\
"attributes": { "source": "cart" },\
"lineItems": [\
{\
"id": "bb44db95-6fbd-4eed-a1ed-4d99bc91250f",\
"amount": 15,\
"quantity": 3,\
"proration": { "spread": [\
{\
"amount": 5,\
"quantity": 3\
}\
] }\
}\
],\
"fulfillments": [\
{\
"id": "bb44db95-6fbd-4eed-a1ed-4d99bc91250f",\
"amount": 10\
}\
]\
}\
] }
headers = {
"x-fabric-tenant-id": "<x-fabric-tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)
JavaScript (Fetch)
const options = {
method: 'PUT',
headers: {
'x-fabric-tenant-id': '<x-fabric-tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
promotions: [\
{\
id: '542ba80a69b8',\
title: '15 Percent All Products',\
code: '15_PERCENT',\
type: 'PERCENTAGE',\
value: 15,\
attributes: {source: 'cart'},\
lineItems: [\
{\
id: 'bb44db95-6fbd-4eed-a1ed-4d99bc91250f',\
amount: 15,\
quantity: 3,\
proration: {spread: [{amount: 5, quantity: 3}]}\
}\
],\
fulfillments: [{id: 'bb44db95-6fbd-4eed-a1ed-4d99bc91250f', amount: 10}]\
}\
]
})
};
fetch('https://api.fabric.inc/v3/carts/{cartId}/promotions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, [\
CURLOPT_URL => "https://api.fabric.inc/v3/carts/{cartId}/promotions",\
CURLOPT_RETURNTRANSFER => true,\
CURLOPT_ENCODING => "",\
CURLOPT_MAXREDIRS => 10,\
CURLOPT_TIMEOUT => 30,\
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\
CURLOPT_CUSTOMREQUEST => "PUT",\
CURLOPT_POSTFIELDS => json_encode([\
'promotions' => [\
[\
'id' => '542ba80a69b8',\
'title' => '15 Percent All Products',\
'code' => '15_PERCENT',\
'type' => 'PERCENTAGE',\
'value' => 15,\
'attributes' => [\
'source' => 'cart'\
],\
'lineItems' => [\
[\
'id' => 'bb44db95-6fbd-4eed-a1ed-4d99bc91250f',\
'amount' => 15,\
'quantity' => 3,\
'proration' => [\
'spread' => [\
[\
'amount' => 5,\
'quantity' => 3\
]\
]\
]\
]\
],\
'fulfillments' => [\
[\
'id' => 'bb44db95-6fbd-4eed-a1ed-4d99bc91250f',\
'amount' => 10\
]\
]\
]\
]\
]),\
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;
}
?>
Golang
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.fabric.inc/v3/carts/{cartId}/promotions"
payload := strings.NewReader("{\n \"promotions\": [\n {\n \"id\": \"542ba80a69b8\",\n \"title\": \"15 Percent All Products\",\n \"code\": \"15_PERCENT\",\n \"type\": \"PERCENTAGE\",\n \"value\": 15,\n \"attributes\": {\n \"source\": \"cart\"\n },\n \"lineItems\": [\n {\n \"id\": \"bb44db95-6fbd-4eed-a1ed-4d99bc91250f\",\n \"amount\": 15,\n \"quantity\": 3,\n \"proration\": {\n \"spread\": [\n {\n \"amount\": 5,\n \"quantity\": 3\n }\n ]\n }\n }\n ],\n \"fulfillments\": [\n {\n \"id\": \"bb44db95-6fbd-4eed-a1ed-4d99bc91250f\",\n \"amount\": 10\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("PUT", 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))
}
Java
HttpResponse<String> response = Unirest.put("https://api.fabric.inc/v3/carts/{cartId}/promotions")
.header("x-fabric-tenant-id", "<x-fabric-tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"promotions\": [\n {\n \"id\": \"542ba80a69b8\",\n \"title\": \"15 Percent All Products\",\n \"code\": \"15_PERCENT\",\n \"type\": \"PERCENTAGE\",\n \"value\": 15,\n \"attributes\": {\n \"source\": \"cart\"\n },\n \"lineItems\": [\n {\n \"id\": \"bb44db95-6fbd-4eed-a1ed-4d99bc91250f\",\n \"amount\": 15,\n \"quantity\": 3,\n \"proration\": {\n \"spread\": [\n {\n \"amount\": 5,\n \"quantity\": 3\n }\n ]\n }\n }\n ],\n \"fulfillments\": [\n {\n \"id\": \"bb44db95-6fbd-4eed-a1ed-4d99bc91250f\",\n \"amount\": 10\n }\n ]\n }\n ]\n}")
.asString();
Ruby
require 'uri'
require 'net/http'
url = URI("https://api.fabric.inc/v3/carts/{cartId}/promotions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["x-fabric-tenant-id"] = '<x-fabric-tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"promotions\": [\n {\n \"id\": \"542ba80a69b8\",\n \"title\": \"15 Percent All Products\",\n \"code\": \"15_PERCENT\",\n \"type\": \"PERCENTAGE\",\n \"value\": 15,\n \"attributes\": {\n \"source\": \"cart\"\n },\n \"lineItems\": [\n {\n \"id\": \"bb44db95-6fbd-4eed-a1ed-4d99bc91250f\",\n \"amount\": 15,\n \"quantity\": 3,\n \"proration\": {\n \"spread\": [\n {\n \"amount\": 5,\n \"quantity\": 3\n }\n ]\n }\n }\n ],\n \"fulfillments\": [\n {\n \"id\": \"bb44db95-6fbd-4eed-a1ed-4d99bc91250f\",\n \"amount\": 10\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body
Response Codes
- 200
- 400
- 404
Successful Response Example
{
"id": "c86f777b-1885-4ddf-961d-542ba80a69b8",
"attributes": {
"name": "wishlist"
},
"configuration": {
"order": {
"validate": {}
},
"product": {
"cacheExpiry": 7776000,
"behaviors": {
"add": "REJECT",
"update": "WARN",
"get": "WARN",
"cacheExpiry": "WARN"
},
"maxQuantity": {
"limit": 100,
"behaviors": {
"add": "REJECT",
"update": "WARN",
"get": "WARN"
}
}
},
"inventory": {
"cacheExpiry": 7776000,
"behaviors": {
"add": "REJECT",
"update": "WARN",
"get": "WARN",
"cacheExpiry": "WARN"
},
"check": "SKU"
},
"tax": {
"cacheExpiry": 7776000,
"behaviors": {
"cacheExpiry": "WARN"
}
},
"promotions": {
"cacheExpiry": 7776000,
"behaviors": {
"cacheExpiry": "WARN"
}
},
"maxQuantity": {
"limit": 100,
"behaviors": {
"add": "REJECT",
"update": "WARN",
"get": "WARN"
}
}
},
"customerContext": {
"id": "109840938",
"segments": [\
{\
"name": "membership",\
"value": [\
"gold",\
"silver"\
]\
}\
],
"attributes": {
"email": "test@gmail.com"
},
"sessionId": "3a5fd2d3-5c96-4e57-b069-7ff2a88c1119"
},
"status": "ACTIVE",
"state": [\
{\
"resource": "CART",\
"resourceId": "c86f777b-1885-4ddf-961d-542ba80a69b8",\
"key": "MISSING_PAYMENT_DETAILS",\
"description": "No payment details have been added to this Cart"\
}\
],
"price": {
"total": 800,
"subtotal": 750,
"tax": 20,
"fulfillments": 25,
"discounts": 10,
"fees": 5,
"adjustments": 10
},
"promotions": {
"total": 32,
"collection": [\
{\
"id": "542ba80a69b8",\
"title": "15 Percent All Products",\
"code": "15_PERCENT",\
"type": "PERCENTAGE",\
"value": 15,\
"attributes": {\
"source": "cart"\
}\
}\
]
}
}
Error Responses
Bad Request
{
"type": "BAD_REQUEST",
"message": "x-fabric-tenant-id is required"
}
Cart Not Found
{
"type": "CART_NOT_FOUND",
"message": "Cart not found"
}
Authorization
Authorization string header required This is the authorization token used to authenticate the request.