Update cart - Fabric
Update cart
cURL
curl --request PATCH \
--url https://api.fabric.inc/v3/carts/{cartId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
--data '
{
"attributes": {
"name": "wishlist"
},
"customerContext": {
"id": "109840938",
"attributes": {
"email": "test@gmail.com"
},
"segments": [
{
"name": "membership",
"value": [
"gold",
"silver"
]
}
],
"sessionId": "3a5fd2d3-5c96-4e57-b069-7ff2a88c1119"
},
"channelId": "12",
"currency": "USD"
}
'
Python
import requests
url = "https://api.fabric.inc/v3/carts/{cartId}"
payload = {
"attributes": { "name": "wishlist" },
"customerContext": {
"id": "109840938",
"attributes": { "email": "test@gmail.com" },
"segments": [
{
"name": "membership",
"value": ["gold", "silver"]
}
],
"sessionId": "3a5fd2d3-5c96-4e57-b069-7ff2a88c1119"
},
"channelId": "12",
"currency": "USD"
}
headers = {
"x-fabric-tenant-id": "<x-fabric-tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)
JavaScript (Fetch API)
const options = {
method: 'PATCH',
headers: {
'x-fabric-tenant-id': '<x-fabric-tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
attributes: {name: 'wishlist'},
customerContext: {
id: '109840938',
attributes: {email: 'test@gmail.com'},
segments: [{name: 'membership', value: ['gold', 'silver']}],
sessionId: '3a5fd2d3-5c96-4e57-b069-7ff2a88c1119'
},
channelId: '12',
currency: 'USD'
})
};
fetch('https://api.fabric.inc/v3/carts/{cartId}', 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/carts/{cartId}",
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([
'attributes' => [
'name' => 'wishlist'
],
'customerContext' => [
'id' => '109840938',
'attributes' => [
'email' => 'test@gmail.com'
],
'segments' => [
[
'name' => 'membership',
'value' => [
'gold',
'silver'
]
]
],
'sessionId' => '3a5fd2d3-5c96-4e57-b069-7ff2a88c1119'
],
'channelId' => '12',
'currency' => 'USD'
]),
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;
}
API Response
200 OK Response Example
{
"id": "c86f777b-1885-4ddf-961d-542ba80a69b8",
"attributes": {
"name": "wishlist"
},
"customerContext": {
"id": "109840938",
"attributes": {"email": "test@gmail.com"},
"segments": [{ "name": "membership", "value": ["gold", "silver"] }],
"sessionId": "3a5fd2d3-5c96-4e57-b069-7ff2a88c1119"
},
"channelId": "12",
"currency": "USD"
}
Error responses
400 BAD_REQUEST Example
{
"type": "BAD_REQUEST",
"message": "x-fabric-tenant-id is required"
}
404 CART_NOT_FOUND Example
{
"type": "CART_NOT_FOUND",
"message": "Cart not found"
}