Skip to main content

Command Palette

Search for a command to run...

Shopify Ajax API

Updated
2 min read
Shopify Ajax API
R

Hey, I’m Rakeshraj Mahakud, a passionate full-stack developer and digital problem solver from India. I specialize in building high-performance web applications and custom Shopify solutions that are not only functional but user-centric.

I enjoy turning complex challenges into clean, scalable code—whether it’s crafting fast-loading storefronts, designing interactive UIs, or building backend logic that just works.

When I’m not coding, you’ll find me exploring the intersection of design and development, leveling up on modern tech stacks, or documenting what I learn to help the dev community.

🔧 Tech I love working with:

JavaScript, TypeScript, Liquid, React, Next.js, Node.js, Express, Shopify theme & app development ,Firebase, MongoDB, REST APIs, GSAP, Splide, Tailwind CSS

💡 On Hashnode, I write about Web development tips & real-world problemsShopify dev hacks & theme customization Performance optimization & clean UI/UX Dev tools, productivity, and beyond

The Ajax API provides a suite of lightweight REST API endpoints for development of Shopify themes.

Use cases

Possible uses of the Ajax API include:

  • Add products to the cart and update the cart item counter.

  • Display related product recommendations.

  • Suggest products and collections to visitors as they type in a search field.

Making requests to the API

The Ajax API accepts two types of HTTP requests:

  • GET requests to read cart and some product data

  • POST requests to update the cart for the current session

For instance, to fetch the current contents of the cart, send a client-side request to the store’s /cart.js endpoint.

var cartContents = fetch(window.Shopify.routes.root + 'cart.js')
  .then(response => response.json())
  .then(data => { return data });

Note

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.

Important :

Shopify’s Ajax API can be used in Shopify themes to carry out actions like adding items to the cart, and displaying suggested products without requiring any page refreshes from buyers.

The Ajax API includes the following endpoints:

  • Cart - Update cart line items, attributes, and notes.

  • Product - Fetch information about any product in the catalog.

  • Product Recommendations - Display recommended products on product pages.

  • Predictive Search - Suggest products, collections, pages and articles to buyers as they type their search queries.

Requirements and limitations

  • This is an unauthenticated API. It doesn’t require access tokens or a client ID to access.

  • There are no hard rate limits on the Ajax API. It’s still subject to Shopify’s standard API abuse-prevention measures.

  • All API responses return JSON-formatted data.

More from this blog

Rakeshraj Mahakud

36 posts