Cart APIs

Salesforce Cart Connect APIs provide developers with a powerful set of APIs to build and customize cart management solutions within the Commerce Cloud platform. These APIs enable developers to effortlessly perform various tasks, including creating, updating, and managing carts. Key functionalities encompass adding or removing items, adjusting quantities, transferring items to wishlists, applying promotions, using coupons, and splitting a cart into multiple delivery groups.

The visibility settings for cart messages enable real-time updates and notifications, ensuring customers stay informed about changes to their carts, such as item availability, price adjustments, or promotional offers.

Moreover, developers can create multiple active carts for the same buyer and choose which cart to serve as the primary one. Additionally, the capability to add up to 100 items in a batch to a cart enhances operational efficiency and scalability.

To enhance the shopping experience further, developers can easily manage coupons associated with a cart, applying or removing them as needed. Similarly, they can gain insights into promotions and apply them at either the cart or individual item level.

To streamline order management and enhance customer satisfaction, developers can organize cart items into delivery groups, simplifying the process of shipping items to multiple addresses. Lastly, a cart can be preserved so that when a guest user logs in as an authenticated customer they retain their guest cart items.

Let's consider a basic scenario for building the cart management flow using Cart APIs. This example covers just a few Cart APIs and doesn't include the entire Cart APIs functionality.

Alt text

In a typical shopping journey, users add products from the Product Listing Page (PLP) or Product Details Page (PDP) to their cart using a POST call on the Cart Item API. Then, they view their cart by clicking the cart icon. If no cart exists for the user, the system creates one using a POST call on the Create Cart API. Next, it retrieves the selected products using a GET call on the Cart Item API.

On the cart page, users can adjust quantities, remove items, or move them to wishlists, which trigger PATCH or DELETE calls on the Cart Item API, or a POST call on the Wishlist API. Promotions can be viewed using GET calls on the Cart Promotions API and Cart Items Promotions API. Valid coupons can be applied with a POST call on the Cart Coupon API. Subsequently, make a POST call on the Cart, Arrange Items API to arrange cart items into delivery groups to split your shipment order. Splitting refers to dividing an order into multiple shipments, and it is often implemented due to products being housed in different locations or specific delivery preferences. After finalizing the cart, users can proceed to checkout.

Here’s a list of Commerce Cart resources:

ResourceSupported HTTP MethodsDescription
/commerce/webstores/{webstoreId}/​cartsPOSTCreate a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}GET, PUT, DELETEGet a cart. Delete a cart. Create an active cart, if one doesn’t exist.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/actions/add-cart-to-wishlistPOSTCopy the products from a cart to a wishlist.
/commerce/webstores/webstoreId/carts​/cartStateorId/actions/clonePOSTClones an existing cart to create a secondary, read-only cart to support Pay Now functionality.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/actions/make-primaryPOSTMake a secondary cart a primary cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/actions/preservePOSTPreserve cart contents when a guest logs in as an authenticated customer.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-couponsGET, POSTGet coupons associated with a cart, and apply a coupon code to a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-coupons/{cartCouponId}DELETEDelete a coupon from a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/messages/actions/set-visibilityPOSTSet the visibility for cart messages.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/productsGETGet the items in a cart, sorted by product ID.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/products/{productId}GETGet cart items of a specific product.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/promotionsGETGet promotions associated with a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-itemsGET, POSTGet the items in a cart. Add an item to a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items/batchPOSTAdd a batch of up to 100 items to a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items/{cartItemId}DELETE, PATCHUpdate or delete an item in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items/promotionsPOSTGet promotions associated with items in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groups/actions/arrange-itemsPOSTArrange cart items into delivery groups.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groupsGET, POSTGet or create a collection of delivery groups in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groups/{deliveryGroupId}DELETE, GET, PATCHGet, delete, or update a delivery group in the cart.

See Also