Apply a specific promotion to all items in a specific cart - Fabric

Apply a specific promotion to all items in a specific cart

cURL Example

curl --request POST \
  --url https://prod.cart.fabric.inc/v2/carts/{cartId}/promos/{promoCode} \
  --header 'Authorization: <authorization>' \
  --header 'x-site-context: <x-site-context>'

Python Example

import requests

url = "https://prod.cart.fabric.inc/v2/carts/{cartId}/promos/{promoCode}"

headers = {
    "x-site-context": "<x-site-context>",
    "Authorization": "<authorization>"
}

response = requests.post(url, headers=headers)

print(response.text)

JavaScript Example

const options = {
  method: 'POST',
  headers: {'x-site-context': '<x-site-context>', Authorization: '<authorization>'}
};

fetch('https://prod.cart.fabric.inc/v2/carts/{cartId}/promos/{promoCode}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

PHP Example

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://prod.cart.fabric.inc/v2/carts/{cartId}/promos/{promoCode}",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => [
    "Authorization: <authorization>",
    "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 Example

package main

import (
    "fmt"
    "net/http"
    "io"
)

func main() {

url := "https://prod.cart.fabric.inc/v2/carts/{cartId}/promos/{promoCode}"

req, _ := http.NewRequest("POST", url, nil)

req.Header.Add("x-site-context", "<x-site-context>")
    req.Header.Add("Authorization", "<authorization>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))
}

Response Examples

Success

{
  "items": [
    {
      "sku": "16B2GS8LD5FDS",
      "items": [
        {
           // Detailed item info
        }
      ],
      "quantity": 1,
      "isPickup": true,
      "cartItemId": "88cded0f-1439-40eb-a7a0-167e8bffdb3b",
      "itemId": "1000000001",
      "title": "Varnet Garden Light Kit",
      "totalPrice": {"currency": "USD", "amount": 100},
      // Other fields... 
    }
  ],
  // Other response fields...
}

Error Responses

Bad Request

{
  "code": "Bad Request",
  "message": "User ID or Cart ID does not exist"
}

Item Not Found

{
  "code": "Cart or item not found",
  "message": "If the issue persists please contact support@fabric.inc."
}

Internal Server Error

{
  "code": "Internal Server Error",
  "message": "An internal error occurred. If the issue persists please contact support@fabric.inc."
}