XM

Add Item to Cart

Path:

POST https://{baseurl}/api-cart/cart/item

Enables your customers to add new items to their digital cart and also increment the item quantity in an existing cart (However, to decrement the item quantity, the Update Cart API is used.) With the first item in the cart, a unique cart ID (represented as _id) is generated and it is required for the subsequent calls.

Note: A maximum of 500 items can be added to a cart. Headers

Content-Type : application/json

x-site-context : { "date": "2020-08-28T02:35:27.787Z", "channel": 12, "account": 5f493c9f30ec2a0007a94fc8", "stage": "sandbox" }

Authorization: The JWT access token from the Login API. This is applicable only for a logged in user (not for guest user).

Parameters

Type : requestBody

Name : The items to be added to the cart.

Required: true

Sample Request - Add Item To Cart as a Guest user

Path:

POST https://{baseurl}/api-cart/cart/item

Request Body:

For a logged in user, Authorization (JWT token from the Login API) must be specified in the header. It is not required for a guest user.

{
"cartId":null,
"items": [
{
"itemId": 170,
"quantity": 1,
"group": [
"123123123123123213212222"
],
"price": {
"sale": 0,
"base": 0,
"discount": {
"price": 0,
"discountAmount": 0,
"promosApplied": []
},
"currency": "USD"
},
"extra": {}
}
]
}

Sample Response (Guest user)

Success Code: 200

Message: OK

Description: You will see this message when items selected are successfully added to the guest cart. In the response for a logged in user, an additional field 'userID' is included (userId is not applicable for a guest user.)

{
"_id": "60e356acc8bcd300099e66a8",
"deleted": false,
"registeredUser": false,
"cartId": 785,
"items": [
{
"price": {
"discount": {
"discountAmount": 0,
"price": 0,
"promosApplied": []
},
"sale": 0,
"base": 100,
"currency": "USD"
},
"sample": false,
"discountedQuantity": 0,
"group": [
"123123123123123213212222"
],
"weightUnit": "lb",
"isPickup": false,
"createdAt": "2021-07-05T18:59:18.717Z",
"updatedAt": "2021-07-05T18:59:57.700Z",
"_id": "60e356acc8bcd300099e66a9",
"itemId": 170,
"quantity": 1,
"priceListId": 100000,
"sku": "testPrice",
"taxCode": "EWPE",
"title": "Pricing",
"weight": 23,
"lineItemId": 1,
"attributeTotalPrice": 0,
"totalPrice": {
"currency": "USD",
"amount": 100
},
"attributes": [],
"id": "60e356acc8bcd300099e66a9"
}
],
"allPromosApplied": [],
"attributes": [],
"createdAt": "2021-07-05T18:59:56.836Z",
"updatedAt": "2021-07-05T18:59:57.715Z",
"__v": 0,
"totalAmount": {
"currency": "USD",
"amount": 100
},
"quantity": 1,
"errors": {
"inventory": [],
"price": [
{
"_id": "60c0f38f4fa92c0008dfd0d5",
"isSoftDeleted": false,
"priceListId": 100000,
"itemId": 170,
"offers": [
{
"price": {
"sale": 0,
"cost": 90,
"currency": "USD",
"base": 100,
"discount": {
"discountAmount": 0,
"price": 0,
"promosApplied": []
}
},
"_id": "60c0f38f4fa92c0008dfd0d6",
"kind": null,
"channel": 12,
"startDate": "2021-06-09T17:15:00.000Z",
"endDate": "2100-01-01T07:59:00.000Z",
"offerCode": 1005,
"range": []
}
]
}
],
"promo": []
}
}

Sample Response (Logged in User)

Success Code: 200

Message: OK

Description: You will see this message when items selected are successfully added to the cart of a logged in user. In the response for a logged in user, an additional field 'userID' is included (userId is not applicable for a guest user.)

{
"_id": "60e35687c8bcd300099e66a6",
"deleted": false,
"registeredUser": true,
"cartId": 784,
"items": [
{
"price": {
"discount": {
"discountAmount": 0,
"price": 0,
"promosApplied": []
},
"sale": 0,
"base": 100,
"currency": "USD"
},
"sample": false,
"discountedQuantity": 0,
"group": [
"123123123123123213212222"
],
"weightUnit": "lb",
"isPickup": false,
"createdAt": "2021-07-05T18:59:18.717Z",
"updatedAt": "2021-07-05T18:59:23.350Z",
"_id": "60e35687c8bcd300099e66a7",
"itemId": 170,
"quantity": 1,
"priceListId": 100000,
"sku": "testPrice",
"taxCode": "EWPE",
"title": "Pricing",
"weight": 23,
"lineItemId": 1,
"attributeTotalPrice": 0,
"totalPrice": {
"currency": "USD",
"amount": 100
},
"attributes": [],
"id": "60e35687c8bcd300099e66a7"
}
],
"userId": "60e3565edb216f0008b538d4",
"allPromosApplied": [],
"attributes": [],
"createdAt": "2021-07-05T18:59:19.095Z",
"updatedAt": "2021-07-05T18:59:23.361Z",
"__v": 0,
"totalAmount": {
"currency": "USD",
"amount": 100
},
"quantity": 1,
"errors": {
"inventory": [],
"price": [
{
"_id": "60c0f38f4fa92c0008dfd0d5",
"isSoftDeleted": false,
"priceListId": 100000,
"itemId": 170,
"offers": [
{
"price": {
"sale": 0,
"cost": 90,
"currency": "USD",
"base": 100,
"discount": {
"discountAmount": 0,
"price": 0,
"promosApplied": []
}
},
"_id": "60c0f38f4fa92c0008dfd0d6",
"kind": null,
"channel": 12,
"startDate": "2021-06-09T17:15:00.000Z",
"endDate": "2100-01-01T07:59:00.000Z",
"offerCode": 1005,
"range": []
}
]
}
],
"promo": []
}
}

Error Code: 404

Message: Item not in stock

Description: You will see this error when the specified item is not in stock.

{
"code": "NOT_IN_STOCK",
"message": "ItemIds 1000000038 are not in stock."
}

Error Code: 404

Message: Not Found

Description: You will see this error when the item or price list ID is not found.

{
"code": "PRICE_LIST_ITEM_ID_NOT_FOUND",
"message": "ItemIds, PriceListIds [1000000052, 100268] not found."
}

Error Code: 404

Message: Not found

Description: You will see this error when Weight or tax code is not found.

{
"code": "ATTRIBUTE_CODE_NOT_FOUND",
"message": "attribute Weight not found for itemId 91."
}

Error Code: 401

Message: Unauthorized

Description: You will see this error when the Authorization (JWT token from the Login APIs) is not valid.

{
"code": "INVALID_AUTHORIZATION_TOKEN",
"message": "Invalid Authorization Token"
}

Error Code: 500

Message: Forbidden

Description: You will see this error when the account number is incorrect in the x-site-context (for a multi-tenent client).

{
"message": "Forbidden"
}

Change Log

  • June - 2021

  • July - 2020 First updated

‚Äč