Add promotion to cart - Fabric
Add promotion to cart
cURL
curl --request PATCH \
--url https://prod01-apigw.yourcompany.fabric.zone/api-cart/cart/apply-promo \
--header 'Content-Type: application/json' \
--header 'x-site-context: <x-site-context>' \
--data '
{
"cartId": "5e5ebf27f1f734055d035833",
"promoName": "CR100"
}
'
Python
import requests
url = "https://prod01-apigw.yourcompany.fabric.zone/api-cart/cart/apply-promo"
payload = {
"cartId": "5e5ebf27f1f734055d035833",
"promoName": "CR100"
}
headers = {
"x-site-context": "<x-site-context>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)
JavaScript (Fetch)
const options = {
method: 'PATCH',
headers: {'x-site-context': '<x-site-context>', 'Content-Type': 'application/json'},
body: JSON.stringify({cartId: '5e5ebf27f1f734055d035833', promoName: 'CR100'})
};
fetch('https://prod01-apigw.yourcompany.fabric.zone/api-cart/cart/apply-promo', 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://prod01-apigw.yourcompany.fabric.zone/api-cart/cart/apply-promo",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'cartId' => '5e5ebf27f1f734055d035833',
'promoName' => 'CR100'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-site-context: <x-site-context>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Go
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://prod01-apigw.yourcompany.fabric.zone/api-cart/cart/apply-promo"
payload := strings.NewReader("{\n \"cartId\": \"5e5ebf27f1f734055d035833\",\n \"promoName\": \"CR100\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("x-site-context", "<x-site-context>")
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))
}
Response Codes
- 200: Success
- 400: Bad Request
- 404: Not Found
- 500: Internal Server Error
Example Response
{
"deleted": false,
"allPromosApplied": [
{
"promoId": "5ddd1a156c5a5fed1e0d91fb",
"promoCode": "10_DOLLORS_OFF_123"
}
],
"items": [
{
"itemId": 1000000012,
"quantity": 2,
"price": {
"currency": "USD",
"base": 15.99,
"discount": {
"price": 10.99,
"discountAmount": 10.99,
"promosApplied": [
{
"unit": "<string>",
"value": 123,
"ON": {
"kind": "SKU",
"value": ""
},
"id": "<string>",
"promoId": "<string>",
"promoCode": "<string>"
}
]
},
"sale": 10.99
},
"group": [
"5ddd1a156c5a5fed1e0d91fb"
],
"totalPrice": {
"currency": "USD",
"amount": 200
},
"title": "item title"
}
],
"registeredUser": false,
"cartId": 4,
"totalAmmount": {
"currency": "USD",
"amount": 200
},
"quantity": 2,
"status": "pending",
"errors": {
"inventory": [],
"price": [],
"promo": []
}
}
Error Example
{
"code": "PROMO_ALREADY_APPLIED",
"message": "TEST20 has already been applied."
}
{
"code": "PROMO_NOT_FOUND",
"message": "The promotion code you entered doesn’t exist."
}
Headers
- x-site-context: Required; a JSON object for context that includes the mandatory
account and optional channel, stage, and date. Example: {"date": "2023-01-01T00:00:00.000Z", "channel": 12, "account": "1234abcd5678efgh9ijklmno","stage":"production"}.
Body
- cartId: Required; e.g.,
"5e5ebf27f1f734055d035833".
- promoName: Required; e.g.,
"CR100".