Update customer - Fabric

Update customer

cURL

curl --request PATCH \
  --url https://api.fabric.inc/v3/carts/{cartId}/customer \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
  --data '
{
  "id": "109840938",
  "attributes": {
    "email": "test@gmail.com"
  },
  "segments": [
    {
      "name": "membership",
      "value": [
        "gold",
        "silver"
      ]
    }
  ],
  "sessionId": "3a5fd2d3-5c96-4e57-b069-7ff2a88c1119"
}
'

Code Examples

Python

import requests

url = "https://api.fabric.inc/v3/carts/{cartId}/customer"

payload = {
    "id": "109840938",
    "attributes": { "email": "test@gmail.com" },
    "segments": [
        {
            "name": "membership",
            "value": ["gold", "silver"]
        }
    ],
    "sessionId": "3a5fd2d3-5c96-4e57-b069-7ff2a88c1119"
}
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({
    id: '109840938',
    attributes: {email: 'test@gmail.com'},
    segments: [{name: 'membership', value: ['gold', 'silver']}],
    sessionId: '3a5fd2d3-5c96-4e57-b069-7ff2a88c1119'
  })
};

fetch('https://api.fabric.inc/v3/carts/{cartId}/customer', 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}/customer",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "PATCH",
  CURLOPT_POSTFIELDS => json_encode([
    'id' => '109840938',
    'attributes' => [
        'email' => 'test@gmail.com'
    ],
    'segments' => [
        [
            'name' => 'membership',
            'value' => ['gold', 'silver']
        ]
    ],
    'sessionId' => '3a5fd2d3-5c96-4e57-b069-7ff2a88c1119'
  ]),
  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;
}

Expected Responses

Successful Response (200)

{
  "id": "109840938",
  "attributes": {
    "email": "test@gmail.com"
  },
  "segments": [
    {
      "name": "membership",
      "value": [
        "gold",
        "silver"
      ]
    }
  ],
  "sessionId": "3a5fd2d3-5c96-4e57-b069-7ff2a88c1119"
}

Bad Request (400)

{
  "type": "BAD_REQUEST",
  "message": "x-fabric-tenant-id is required"
}

Not Found (404)

{
  "type": "CART_NOT_FOUND",
  "message": "Cart not found"
}

Authorization

Authorization: string (header, required) - This is the authorization token for authentication.

Additional Headers