Salesforce Commerce Cart API

Salesforce Cart Connect APIs provide developers with a powerful set of APIs to build and customize cart management solutions within the B2B Commerce 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.

Use Case

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.

Diagram of the cart management API workflow for B2B and D2C Commerce

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.

Resources

Here’s a list of Commerce Cart resources:

Resource Supported HTTP Methods Description
/commerce/webstores/{webstoreId}/​carts POST Create a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId} GET Get a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId} DELETE Delete a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId} PUT Create an active cart, if one doesn’t exist.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/actions/add-cart-to-wishlist POST Copy the products from a cart to a wishlist.
/commerce/webstores/webstoreId/carts​/cartStateorId/actions/clone POST Clones an existing cart to create a secondary, read-only cart to support Pay Now functionality.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/actions/make-primary POST Make a secondary cart a primary cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/actions/preserve POST Preserve cart contents when a guest logs in as an authenticated customer.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-coupons GET Get coupons associated with a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-coupons POST Apply a coupon code to a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-coupons/{cartCouponId} DELETE Delete a coupon from a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/messages/actions/set-visibility POST Set the visibility for cart messages.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/products GET Get the items in a cart, sorted by product ID.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/products/{productId} GET Get cart items of a specific product.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/inventory-reservations DELETE Delete an inventory reservation from the cart.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/inventory-reservations PUT Create and update an inventory reservation from the cart.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/delivery-groups/actions/itemDistributions POST Distribute cart items into delivery groups.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/promotions GET Get promotions associated with a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items GET Get the items in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items POST Add an item to a cart.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/cart-items/{cartItemId}/children GET Retrieves all child items associated with a specified cart item. This API is supported only for product bundles.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items/batch POST Add a batch of up to 100 items to a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items/{cartItemId} DELETE Update or delete an item in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items/{cartItemId} PATCH Update or delete an item in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/cart-items/promotions POST Get promotions associated with items in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groups/actions/arrange-items POST Arrange cart items into delivery groups.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groups GET Get or create a collection of delivery groups in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groups POST Get or create a collection of delivery groups in a cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groups/{deliveryGroupId} GET Get a delivery group in the cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groups/{deliveryGroupId} DELETE Delete a delivery group in the cart.
/commerce/webstores/{webstoreId}/carts​/{cartStateOrId}/delivery-groups/{deliveryGroupId} PATCH Update a delivery group in the cart.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/actions/calculate POST Perform a complete cart calculation based on the cart status.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/actions/evaluate-shipping POST Evaluate the shipping costs for a cart.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/actions/evaluate-taxes POST Evaluate taxes for a cart.
/commerce/webstores/{webstoreId}/carts/compact-summary GET Retrieve compact cart summary for an existing cart.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/cart-items/actions/apply-configuration POST Apply a saved configuration context to a cart item.
/commerce/webstores/{webstoreId}/carts/{activeCartOrId}/quotes POST Create a new quote from an active cart by converting cart items into quote line items.
/commerce/webstores/{webstoreId}/quotes GET Retrieve all quotes associated with a given account.
/commerce/webstores/{webstoreId}/quotes/{quoteId} GET Retrieve the details of a specific quote using the quote ID provided in the path parameter.

See Also