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=!DateCreated
Use the ID of most recently created
Order
If 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
Cart
always represents an unsubmittedOrder
, any action taken on theCart
is a proxy to take action on the corresponding orderWith a few exceptions,
Cart
endpoints will not return null or 404GET v1/cart
will return an emptyOrder
with a null ID if the shopper does not yet have an unsubmitted orderThis
Order
with 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/lineitems
will return an empty list even if the order does not yet exist
PUT v1/cart
can be used to immediately create anOrder
, but should usually be deferred until an item is addedPOST v1/cart/lineitems
orPUT v1/cart/lineitems
will add an item to theCart
, with the benefit of creating the unsubmittedOrder
if it does not exist
Single Cart Shopping Flow Example
Call
GET v1/cart
on initial page load to display Order.LineItemCount on the cart iconCall
POST v1/cart/lineitems
to add an item to theCart
Calls to
POST v1/cart/payments
,POST v1/cart/validate
, etc. to prepare theCart
for 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=Unsubmitted
to 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/cart
only 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/ABC
to designate thatOrder
as the activeCart
Call
POST v1/cart/lineitems
to add an item toOrder.ID: ABC
Call
PUT v1/cart/123
to change the activeCart
toOrder.ID: 123
Call
POST v1/cart/lineitems
to add an item toOrder.ID: 123
Calls to
POST v1/cart/payments
,POST v1/cart/validate
, etc. to prepareOrder.ID: 123
for submissionCall
POST v1/cart/submit
to submitOrder.ID: 123
Order.ID: ABC
is now theCart
, as it is the only unsubmittedOrder
remaining
In the event that multiple unsubmitted
Orders
remain, usingPUT v1/cart/{orderID}
would designate whichOrder
should be theCart
If none is designated, the most recently created unsubmitted
Order
will 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
Cart
endpoints will return the most recently created unsubmittedOrder
, when following best practices there would only be oneFor Multi-Cart Shopping experiences, the
Cart
endpoints return theOrder
designated as theCart
OR 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