RESTful requests are a standardized way for applications to communicate with servers over the internet. These requests use different methods to perform specific actions:
- GET: Fetch information from the server.
- POST: Creates information to the server.
- PUT: Updates existing information on the server.
- DELETE: Deleting information from the server.
Fetch all available products
Next, we need to know the ID of the product we want to order. For this example, I decided to go with the product named Beanie with Logo, one of the sample products in WooCommerce core. To list all available products, we make the following request: First, we need to know the ID of the product we want that can be used to add the item to the cart. I can get a list of products from/wp-json/cocart/v2/products. This returns products in JSON format and shows product IDs and pricing information:

Requesting available products in store
Add a product to the cart
We can then pick which product we’d like to add to the cart, and go ahead and add it via the/wp-json/cocart/v2/cart/add-item route. This will either add the item to the cart, returning the new updated cart object, or return an error response if something went wrong.
After making the request, we can see that the desired product had been added to the cart:

Cart response along with the added item
Collecting and tracking the cart key
There are two ways you can get the cart key. The first is via the cart response where you seecart_key. The second is via the returned response headers. There you will need to look for CoCart-API-Cart-Key. In this case the cart key is {cart_key}.
This cart key is what we need to keep track of the cart session for the guest customer. The reason for that is because we don’t rely on WooCommerce session cookie to store the cart key for us. Doing this allows more freedom for developers and control on how they want to build their headless store.
Once you get the cart_key, you must store it somewhere in your application. It can be:
- Browser Storage
- using a cookie
- LocalStorage (with encryption)
- SessionStorage (for temporary sessions)
- Storage Libraries
- localForage - Offline storage with fallbacks
- PouchDB - Offline-first database
- Native Storage
Adding customer information
With the item now in the cart, we can attempt to add customer information using the/wp-json/cocart/v2/cart/update?cart_key=<cart_key>&namespace=update-customer endpoint.
Notice that I placed the cart key as global parameter. You can apply the cart key via the headers to if you prefer.
s_ prefix in front to identify the field is for shipping. Followed by setting the field ship_to_different_address as true.
A different shipping address can only be applied if you have CoCart Plus installed.
Load cart into store
123Resources
- Get Cart Info (/cocart/v2/cart)
- Add Item to Cart (/cocart/v2/cart/add-item)
- List Products (/cocart/v2/products)