Update items - Fabric

Update items

cURL

curl --request PATCH \
  --url https://api.fabric.inc/v3/orchestrator/carts/{cartId}/items \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-fabric-channel-id: <x-fabric-channel-id>' \
  --header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
  --data '
{
  "lineItems": [
    {
      "id": "<string>",
      "refId": "<string>",
      "priceListId": "<string>",
      "quantity": 123,
      "price": {
        "total": 1570,
        "subtotal": 1530,
        "tax": 0,
        "fulfillments": 40,
        "discounts": 0,
        "fees": 0,
        "adjustments": 0
      },
      "fulfillment": {
        "id": "<string>"
      },
      "attributes": {}
    }
  ]
}
' 

Python

import requests

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

payload = { "lineItems": [
        {
            "id": "<string>",
            "refId": "<string>",
            "priceListId": "<string>",
            "quantity": 123,
            "price": {
                "total": 1570,
                "subtotal": 1530,
                "tax": 0,
                "fulfillments": 40,
                "discounts": 0,
                "fees": 0,
                "adjustments": 0
            },
            "fulfillment": { "id": "<string>" },
            "attributes": {}
        }
    ] }
headers = {
    "x-fabric-tenant-id": "<x-fabric-tenant-id>",
    "x-fabric-channel-id": "<x-fabric-channel-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>',
    'x-fabric-channel-id': '<x-fabric-channel-id>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    lineItems: [
      {
        id: '<string>',
        refId: '<string>',
        priceListId: '<string>',
        quantity: 123,
        price: {
          total: 1570,
          subtotal: 1530,
          tax: 0,
          fulfillments: 40,
          discounts: 0,
          fees: 0,
          adjustments: 0
        },
        fulfillment: {id: '<string>'},
        attributes: {}
      }
    ]
  })
};

fetch('https://api.fabric.inc/v3/orchestrator/carts/{cartId}/items', 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/orchestrator/carts/{cartId}/items",
  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([
    'lineItems' => [
        [
                'id' => '<string>',
                'refId' => '<string>',
                'priceListId' => '<string>',
                'quantity' => 123,
                'price' => [
                                'total' => 1570,
                                'subtotal' => 1530,
                                'tax' => 0,
                                'fulfillments' => 40,
                                'discounts' => 0,
                                'fees' => 0,
                                'adjustments' => 0
                ],
                'fulfillment' => [
                                'id' => '<string>'
                ],
                'attributes' => [

]
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json",
    "x-fabric-channel-id: <x-fabric-channel-id>",
    "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 Response

{
  "id": "0e49199c-5849-4211-abe6-a97a3c4dcc56",
  "attributes": {},
  "configuration": {
    "order": {
      "validate": {}
    },
    "product": {
      "cacheExpiry": 7776000,
      "behaviors": {
        "add": "REJECT",
        "update": "WARN",
        "get": "WARN",
        "cacheExpiry": "WARN"
      },
      "maxQuantity": {
        "limit": 100,
        "behaviors": {
          "add": "REJECT",
          "update": "WARN",
          "get": "WARN"
        }
      }
    },
    "inventory": {
      "cacheExpiry": 7776000,
      "behaviors": {
        "add": "REJECT",
        "update": "WARN",
        "get": "WARN",
        "cacheExpiry": "WARN"
      },
      "check": "SKU"
    },
    "tax": {
      "cacheExpiry": 7776000,
      "behaviors": {
        "cacheExpiry": "WARN"
      }
    },
    "promotions": {
      "cacheExpiry": 86400,
      "behaviors": {}
    }
  },
  "customerContext": {
    "id": "109840938",
    "segments": [
      {
        "name": "membership",
        "value": [
          "gold",
          "silver"
        ]
      }
    ],
    "attributes": {
      "email": "test@gmail.com"
    },
    "sessionId": "3a5fd2d3-5c96-4e57-b069-7ff2a88c1119"
  },
  "status": "ACTIVE",
  "state": [
    {
      "resource": "CART",
      "resourceId": "c86f777b-1885-4ddf-961d-542ba80a69b8",
      "key": "MISSING_PAYMENT_DETAILS",
      "description": "No payment details have been added to this Cart"
    }
  ],
  "price": {
    "total": 1570,
    "subtotal": 1530,
    "tax": 0,
    "fulfillments": 40,
    "discounts": 0,
    "fees": 0,
    "adjustments": 0
  }
}

Errors

{
  "type": "UNPROCESSABLE_ORCHESTRATION",
  "message": "4xx Error from orchestration dependency",
  "errors": [
    {
      "type": "NOT_FOUND",
      "message": "404 Not Found from POST https://api.fabric.inc/carts/326949f9-7c25-4983-9848-b2061abb217dl/items/batch",
      "code": 404,
      "source": "POST https://api.fabric.inc/carts/326949f9-7c25-4983-9848-b2061abb217dl/items/batch",
      "details": {
        "type": "CART_NOT_FOUND",
        "message": "Cart not found",
        "errors": []
      }
    }
  ]
}