Adding a product to a cart

Learn how to add a product to a cart.

This section guides you through adding a product to a cart using the Commerce API. By making a POST request to the specified endpoint with the appropriate product identifier, you can seamlessly integrate the capability of adding products to a shopper's cart within your application.

See Gifting for details if you want to add a gift product to the cart.

Add a product to a cart using the product identifier

To add a product to a cart using the product identifier,

  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?productId={productId} request to the /v1/shoppers/me/carts/active request. Replace {productId} with the actual product identifier and {Your_API_Key} with your API key. For product combinations, replace the {productId} with the combination product's identifier. The response will detail the product information under lineItem and any components under the component object. See Update current cart query parameters for more details.

Here's a basic example using cURL:

curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/carts
/active?productId={productId}' \
--header 'authorization: Basic {Your_API_Key}'\

A successful request will return a 200 OK response with cart details, including line items and pricing information.

Last updated