Add or update specific item attribute - Fabric

Add or Update Specific Item Attribute

cURL

curl --request PATCH \
  --url https://prod.cart.fabric.inc/v2/carts/{cartId}/item/attribute \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --header 'x-site-context: <x-site-context>' \
  --data '
[
  {
    "lineItemId": 1,
    "attributeId": "60c2a368eb2ec30008ae70a2",
    "attributeValue": "true"
  }
]
'```

### Python

```python
import requests

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

payload = [\
    {\
        "lineItemId": 1,\
        "attributeId": "60c2a368eb2ec30008ae70a2",\
        "attributeValue": "true"\
    }\
]
headers = {
    "x-site-context": "<x-site-context>",
    "Authorization": "<authorization>",
    "Content-Type": "application/json"
}

response = requests.patch(url, json=payload, headers=headers)

print(response.text)

JavaScript

const options = {
  method: 'PATCH',
  headers: {
    'x-site-context': '<x-site-context>',
    Authorization: '<authorization>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify([\
    {lineItemId: 1, attributeId: '60c2a368eb2ec30008ae70a2', attributeValue: 'true'}\
  ])
};

fetch('https://prod.cart.fabric.inc/v2/carts/{cartId}/item/attribute', 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://prod.cart.fabric.inc/v2/carts/{cartId}/item/attribute",\
  CURLOPT_RETURNTRANSFER => true,\
  CURLOPT_ENCODING => "",\
  CURLOPT_MAXREDIRS => 10,\
  CURLOPT_TIMEOUT => 30,\
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\
  CURLOPT_CUSTOMREQUEST => "PATCH",\
  CURLOPT_POSTFIELDS => json_encode([\
    [\
        'lineItemId' => 1,\
        'attributeId' => '60c2a368eb2ec30008ae70a2',\
        'attributeValue' => 'true'\
    ]\
  ]),\
  CURLOPT_HTTPHEADER => [\
    "Authorization: <authorization>",\
    "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://prod.cart.fabric.inc/v2/carts/{cartId}/item/attribute"

payload := strings.NewReader("[\n  {\n    \"lineItemId\": 1,\n    \"attributeId\": \"60c2a368eb2ec30008ae70a2\",\n    \"attributeValue\": \"true\"\n  }\n]")

req, _ := http.NewRequest("PATCH", url, payload)

req.Header.Add("x-site-context", "<x-site-context>")
    req.Header.Add("Authorization", "<authorization>")
    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

Example Response

{
  "items": [{
    "sku": "16B2GS8LD5FDS",
    "title": "Light Cover",
    "quantity": 1,
    "price": 100,
    "currency": "USD"
  }],
  "totalAmount": 95,
  "cartId": "d7e78a21-bee3-4448-bf1c-d5b5461dbda2"
}