Cart endpoint API v2

This page describes the v2 cart endpoint, which can be used to interact with your external e-commerce solution’s REST shopping cart service.

In v2, cartId is a path parameter instead of form parameter in the REST calls. For example the v1 /carts/items becomes in v2 /carts/{cartId}/items. The other parts of the call are unchanged.

With this endpoint, you can:

  • Create a cart anonymously or as an authenticated user.

  • Add an item to a cart.

  • Change the quantity of items in a cart.

  • Remove an item from a cart.

Magento is now Adobe Commerce, powered by Magento. In the examples and configuration below, we refer to Adobe Commerce as Magento.

POST

Post cart as an anonymous user

Creates a cart as an anonymous user.

Request URL

/.rest/ecommerce/v2/carts/

Parameters

Parameter Description Type Data Type Connector

definitionName

required

The definition name.

query

string

commercetools

Magento

connectionName

required

The connection name.

query

string

commercetools

Magento

anonymousId

required

Identifies the cart belonging to an anonymous user.

header

string

commercetools

currencyCode

required

A three-digit currency code as per ↗ ISO 4217.

form

string

commercetools

Post cart as an authenticated user

Creates a cart for a registered user.

Request URL

/.rest/ecommerce/v2/carts/

Parameters

Parameter Description Type Data Type Connector

definitionName

required

The definition name.

query

string

commercetools

Magento

connectionName

required

The connection name.

query

string

commercetools

Magento

userId

required commercetools: The unique ID of the user.

Magento: Access token.

header

string

commercetools

Magento

currencyCode

required

A three-digit currency code as per ↗ ISO 4217.

form

string

commercetools

GET

Get a cart by ID

Returns a cart by its ID.

Request URL

/.rest/ecommerce/v2/carts/{cartId}

Parameters

Parameter Description Type Data Type Connector

cartId

required

commercetools: The unique ID of the cart.

Magento: quote ID.

path

string

commercetools

Magento (anonymous)

definitionName

required

The definition name

query

string

commercetools

Magento

connectionName

required

The connection name

query

string

commercetools

Magento

Get a cart by user ID

Returns a cart by user ID.

Request URL

/.rest/ecommerce/v2/carts/user

Parameters

Parameter Description Type Data Type Connector

userId

required

commercetools: the unique ID of the user.

Magento: the Access token.

header

string

commercetools

Magento

definitionName

required

The definition name.

query

string

commercetools

Magento

connectionName

required

The connection name.

query

string

commercetools

Magento

POST

Post an item to cart

Adds an item to a cart.

Request URL

/.rest/ecommerce/v2/carts/{cartId}/items

Parameters

Parameter Description Type Data Type Connector

productId

required

commercetools: the unique ID of the product.

Magento: SKU of the product.

form

string

commercetools

Magento

cartId

required in commercetools, only for anonymous in Magento

The unique ID of the cart.

path

string

commercetools

Magento

quantity

required, default is 1

Quantity of products added to the cart.

form

string

commercetools

Magento

quoteId

required

The quote id.

form

string

Magento

definitionName

required

The definition name.

query

string

commercetools

Magento

connectionName

required

The connection name.

query

string

commercetools

Magento

accessToken

required

The access token.

header

string

Magento

Post the quantity of items

Updates the quantity of items in a cart.

Request URL

/.rest/ecommerce/v2/carts/{cartId}/items/{itemId}

Parameters

Parameter Description Type Data Type Connector

itemId

required

The ID of an item in a cart.

path

string

commercetools

Magento

cartId

required in commercetools, only for anonymous in Magento

The unique ID of the cart.

path

string

commercetools

Magento

quantity

required

New quantity of products in the cart.

form

string

commercetools

Magento

quoteId

required

The quote ID.

form

string

Magento

definitionName

required

The definition name.

query

string

commercetools

Magento

connectionName

required

The connection name.

query

string

commercetools

Magento

accessToken

required for authenticated users

The access token.

header

string

Magento

DELETE

Delete an item from a cart

Removes an item from a cart.

Request URL

/.rest/ecommerce/v2/carts/{cartId}/items/{itemId}

Parameters

Parameter Description Type Data Type Connector

itemId

required

ID of an item in the cart.

path

string

commercetools

Magento

cartId

required

The unique ID of the cart.

path

string

commercetools

definitionName

required

The definition name.

query

string

commercetools

Magento

connectionName

required

The connection name.

query

string

commercetools

Magento

accessToken

required

The access token.

header

string

Magento - authenticated cart

quoteId

required

The quote id.

form

string

Magento - anonymous

Feedback