The Ajax API provides a suite of lightweight REST API endpoints for development of Shopify themes. The Ajax API can only be used by themes that are hosted by Shopify. You can't use the Ajax API on a Shopify custom storefront.
Key Functionalities:
- Adding items to the cart
- Updating item quantities in the cart
- Removing items from the cart
- Retrieving the current cart state
Common Endpoints:
/cart/add.js: Add items to the cart
/cart/update.js: Update items in the cart
/cart/change.js: Change items in the cart (can be used to add, update, or remove)
/cart.js: Get the current cart state
fetch(window.Shopify.routes.root + 'cart.js')
.then(response => response.json())
.then(cart => {
console.log(cart);
})
.catch(error => console.error('Error fetching cart:', error));
Top comments (0)