Creating or updating a cart

Learn how to create or update a cart.

Managing a cart is crucial for providing a seamless shopping experience. The process involves interacting with the Commerce API, whether creating a new cart or updating an existing one. This guide will cover the API requests and responses needed to create or update a cart successfully. Follow along to ensure your cart operations are smooth and efficient. If you want to add a gift to a cart, see Gifting.

Creating a cart

Creating a cart involves several steps, from obtaining an access token to verifying the cart's creation. This guide will walk you through the necessary API requests and responses to ensure a successful cart creation process.

To create a cart:

  1. Send a POST /oauth20/token request to obtain an access token. You must include this token in all subsequent cart interactions.

  2. After receiving the token, verify the cart creation by sending a GET /v1/shoppers/me/carts/active request. Replace {Your_API_Key} with your actual access token.

You can use cURL for this process, as shown below:

curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/carts/active' \
--header 'Content-Type:  application/json' \
--header 'authorization: Basic {Your_API_Key}\

A successful request returns a 200 OK response, confirming the creation of the cart with various URIs for further interactions, such as managing payment methods and submitting the cart.

Updating a cart

Updating an existing cart allows you to add various elements such as products, coupon codes, billing, and shipping addresses. Below, you'll find a comprehensive guide on how to update your cart using cURL effectively. Ensure you have the API key and permission to modify the cart details.

You can use the POST /v1/shoppers/me/carts/active resource to add products, coupon codes, billing/shipping addresses, and offers to a customer's cart. You can leverage all of the resources contained in the Cart to modify specific cart data elements. See the cart query parameters for more information.

To update a cart:

  1. Ensure you obtain your access token during cart creation. For instructions on generating the access token, refer to Creating a cart.

  2. Send a POST /v1/shoppers/me/carts/active request. Replace {Your_API_Key} with your actual API key. Include the necessary data parameters to modify the cart's contents as required. This allows you to add products, coupon codes, billing/shipping addresses and offers to a customer's cart.

You can use cURL for this process, as shown below:

A successful request returns a 200 OK response, confirming the updated cart details, including line items, pricing, addresses, etc.

Additional information

For additional information on updating a cart, see the following topics:

Last updated

Was this helpful?