Introducing the Cart API
Published by DJ Steinmetz on September 1, 2022
Introducing new endpoints aimed at simplifying development of the shopping experience. Cart is a usability enhancement which provides endpoints to interact with a given order. We consider it best practice to use Cart when implementing single-cart shopping experiences; however Cart can also be implemented for multi-cart shopping.
Before Cart, determining which Order should be used when the shopper adds an item required several API calls; which typically looked something like this:
GET v1/orders/{direction}?Status=Unsubmitted&SortBy=!DateCreatedUse the ID of most recently created
OrderIf none exists,
call POST v1/orders/{direction}Call
POST v1/orders/{direction}/{orderID}/lineitems
One of the primary aims of the new Cart resource is to reduce this very common workflow into a single API call:
Call POST v1/cart/lineitems
Key Highlights
Cartalways represents an unsubmittedOrder, any action taken on theCartis a proxy to take action on the corresponding orderWith a few exceptions,
Cartendpoints will not return null or 404GET v1/cartwill return an emptyOrderwith a null ID if the shopper does not yet have an unsubmitted orderThis
Orderwith a null ID does not actually exist in OrderCloud, but is returned as a convenience for the developer to be able to utilize the order model if needed for things like displaying the count of items on a cart icon
GET v1/cart/lineitemswill return an empty list even if the order does not yet exist
PUT v1/cartcan be used to immediately create anOrder, but should usually be deferred until an item is addedPOST v1/cart/lineitemsorPUT v1/cart/lineitemswill add an item to theCart, with the benefit of creating the unsubmittedOrderif it does not exist
Single Cart Shopping Flow Example
Call
GET v1/carton initial page load to display Order.LineItemCount on the cart iconCall
POST v1/cart/lineitemsto add an item to theCartCalls to
POST v1/cart/payments,POST v1/cart/validate, etc. to prepare theCartfor submissionCall
POST v1/cart/submit
Please note:
In a single cart shopping experience Cart endpoints should be used as an alternative to Order endpoints, in order to avoid creating multiple unsubmitted orders for a given user. In the event that multiple unsubmitted orders exist, the most recently created unsubmitted order will be selected as the Cart. If the Cart is submitted, the next unsubmitted order will become the Cart which made lead to confusion for the shopper.
Multi-Cart Shopping Flow Example
Call
GET v1/orders/{direction}?Status=Unsubmittedto get the shopper's unsubmittedOrders
for this purposes of this example, two Orders are returned. Order.ID: ABC and Order.ID: 123
if multiple unsubmitted orders do not yet exist, you will need to create them using
POST v1/orders/{direction}orPUT v1/orders/{direction}/{orderID}PUT v1/cartonly creates a new cart if none exists andPUT v1/cart/{orderID}is only used to designate an unsubmitted order as the active cart
Call
PUT v1/cart/ABCto designate thatOrderas the activeCartCall
POST v1/cart/lineitemsto add an item toOrder.ID: ABCCall
PUT v1/cart/123to change the activeCarttoOrder.ID: 123Call
POST v1/cart/lineitemsto add an item toOrder.ID: 123Calls to
POST v1/cart/payments,POST v1/cart/validate, etc. to prepareOrder.ID: 123for submissionCall
POST v1/cart/submitto submitOrder.ID: 123Order.ID: ABCis now theCart, as it is the only unsubmittedOrderremaining
In the event that multiple unsubmitted
Ordersremain, usingPUT v1/cart/{orderID}would designate whichOrdershould be theCartIf none is designated, the most recently created unsubmitted
Orderwill be theCart
Multi-Cart is not supported for Anonymous Shopping
New Endpoints
All of the Cart endpoints (with the exception of PUT v1/cart/{orderID} are proxy endpoints to existing Orders endpoints, with the added benefit of not needing to pass a Direction or orderID.
For Single-Cart Shopping experiences, the
Cartendpoints will return the most recently created unsubmittedOrder, when following best practices there would only be oneFor Multi-Cart Shopping experiences, the
Cartendpoints return theOrderdesignated as theCartOR if none has been designated, it will return the most recently created unsubmittedOrder
New Endpoint | Corresponding Order Endpoint | RequestBody | Behavior |
|---|---|---|---|
|
| None | Returns the |
|
|
| Creates the |
| None | None | For Multi-Cart shopping experiences only. Designates an unsubmitted |
|
|
| Partially updates the |
|
| None | Deletes the |
|
| None | Returns a list of |
|
| None | Returns a single |
|
|
| Creates a new |
|
|
| Creates or Updates a |
|
|
|
|
|
| None | Deletes a |
|
| None | Returns the |
|
| None | Estimates Shipping Costs for the |
|
|
| Sets a Shipping Method for the |
|
|
| Sets a one time shipping address for the |
|
|
| Partially updates a one time shipping address for the |
|
|
| Sets a one time billing address for the |
|
|
| Partially updates a one time shipping address for the |
|
| None | Calculates the |
|
| None | Lists |
|
| None | Returns a single |
|
|
| Creates a |
|
|
| Partially updates a |
|
| None | Deletes a |
|
|
| Creates a |
|
| None | Deletes a |
|
| None | Lists |
|
| None | Adds a |
|
|
| Updates the FromUser associated with the |
|
| None | Validates the |
|
| None | Submits the |
Still have questions?
Ask in our Community Channel