Cart API
Introduction
The Cart API provides endpoints to manage a cart, from creating a cart, to adding a discount.
For more details about this API usage, check out the API documentation
Preparation
- Have an authenticated token from the authentication service, this token should be used as an authorization
bearer token
in the header for every request done to this API (more information about the authorization service here).
Create Cart
To create a new cart, simply make a POST request to the endpoint /cart
. There are two ways to create a cart, you can either
create an empty cart or with items. To create a cart with items, you need to pass a list of items in the body of the request.
Example request:
For the response, we expect to get the created cart. One important attribute is the cartId
, which can be used in other requests
later to manage the cart. To see the full response, go to the cart API documentation.
Manage a Cart
After creating a cart, at some point you want to get information about it. To get the cart information, make a
GET request to /cart/{cartId}
. Make sure to pass a valid cartId
in the request.
It is also possible to set the status of the cart to discarded. For that, make a DELETE request to /cart/{cartId}
.
After discarding a cart, it cannot be used anymore for any operation. So be sure you really want to discard the cart.
Manage Items of Cart
After having created a cart, you can then manage the item list. For example, you can add more items by making a POST request to the /cart/{cartId}/items
endpoint.
In the request body, provide a list of items that you want to add to the cart, the same as you saw in the create cart request body above.
You can also discard or update a specific item in the list.
- To discard an item you need to do a DELETE request to
/cart/{cartId}/items/{positionId}
and provide thecartId
and thepositionId
of the item that you want to discard. - It is also possible to manually change the base price of a position. For that, make a PATCH request to
/cart/{cartId}/items/{positionId}
and provide thevalue
andcurrency
for the new base price.
Example request:
Manage Discounts
To manage a discount, you need a discountId
. You can get the id by using the Masterdata Service.
There are two ways on how to use a discount for a cart, you can either add a discount to the cart itself or just to one specific item.
To add a discount to the cart, you need to make a POST request to the /cart/{cartId}/discounts
endpoint and provide the discountId
and other necessary values in the request body.
Example request:
If you just want to add a discount to a specific item in the cart, you need to make a POST request to /cart/{cartId}/items/{positionId}/discounts
.
Here you need to provide the positionId
, the cartId
and also the request body as shown in the example above.
To remove a discount from the cart or a specific item, you need to make a DELETE request to /cart/{cartId}/items/{positionId}/discounts/{discountId}
.
If you want to delete a cart based discount, then provide the cartId
, discountId
and the positionId
with the value 0
.
For a specific item, change the positionId
to the item where you want to remove the discount from.
note
Keep in mind, if you applied a cart based discount, you can't remove it per item based.