How to Use the Shopify API and Make GraphQL Requests

April 9, 2025

With REST being phased out, mastering GraphQL is more important than ever. If you've ever wanted to build custom Shopify apps or automate store management, this guide will teach you everything you need to know about Shopify’s API and how to make GraphQL requests.

Here’s what we’ll cover:

  • What the Shopify API is
  • The basics of GraphQL
  • How to write your first queries and mutations
  • Using Shopify’s GraphiQL App to test queries
  • How to send API requests from your code
  • The latest updates and features from Shopify

Let’s dive in!

What is the Shopify API?

To understand how the Shopify API works, let’s quickly break down how Shopify itself is structured:

  • Storefront (Frontend) → Where customers browse products
  • Admin Area (Backend) → Where store owners manage products, orders, and settings
  • Shopify Database → Stores all the data (products, collections, customers, orders, etc.)

If you want to extend Shopify’s functionality (e.g., auto-generate invoices or sync inventory across multiple stores), you can’t modify Shopify’s backend code directly. Instead, you need to create external apps that interact with the store’s database through the API.

This is where GraphQL comes in.

What is GraphQL and Why Use It?

GraphQL is the query language we use to communicate with the Shopify API. It allows us to:

  • Request only the data we need (unlike REST, which is often returns unnecessary data)
  • Reduce the number of API requests (since we can retrieve multiple fields in a single query)
  • Write flexible and efficient queries that scale well

There are two main types of GraphQL operations: Queries and Mutations.

Queries (Fetching Data)

Queries are used to retrieve data from the Shopify database. They don’t modify anything; they just read information.

Example: Get the IDs of the 5 most recent orders

query GetMostRecentOrders {
  orders(first: 5, sortKey: CREATED_AT, reverse: true) {
    edges {
      node {
        id
        createdAt
      }
    }
  }
}

Mutations (Modifying Data)

Mutations allow us to create, update, or delete data.

Example: Change the title of a product

mutation UpdateProductTitle {
  productUpdate(input: {
    id: "gid://shopify/Product/123456789",
    title: "New Product Title"
  }) {
    product {
      id
      title
    }
    userErrors {
      field
      message
    }
  }
}

How to Get Started with GraphQL in Shopify

The fastest way to start writing GraphQL queries is by using the Shopify GraphiQL App.

Step 1: Install the GraphiQL App

  1. Go to the Shopify App Store and install GraphiQL.
  2. Enter your Shopify store URL and grant necessary permissions.
  3. Select the Admin API and the latest API version.

Step 2: Explore the API Schema

The GraphQL Explorer inside GraphiQL helps you discover available fields and objects.

  1. Open GraphiQL and click on GraphQL Explorer.
  2. Browse through available fields and objects.
  3. Select the fields you need, and GraphiQL will auto-generate your query!

Step 3: Run Your First Query

Use the play button to execute your query and view the response.

Example Response:

{
  "data": {
    "orders": {
      "edges": [
        { "node": { "id": "12345" } },
        { "node": { "id": "67890" } }
      ]
    }
  }
}

Boom! 🎉 You’ve just made your first GraphQL request.

Making GraphQL Requests in Your Code

Most real-world apps send GraphQL requests from code, not just inside GraphiQL. Here’s how to do it with plain Javascript:

async function fetchShopifyData() {
  const shopifyGraphQLEndpoint = "https://YOUR_SHOP.myshopify.com/admin/api/2025-01/graphql.json";
  const accessToken = "YOUR_ACCESS_TOKEN";
  
  const query = `{
    shop {
      name
      primaryDomain {
        url
      }
    }
  }`;
  
  const response = await fetch(shopifyGraphQLEndpoint, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-Shopify-Access-Token": accessToken,
    },
    body: JSON.stringify({ query })
  });
  
  const data = await response.json();
  console.log(data);
}

fetchShopifyData();

Replace YOUR_SHOP and YOUR_ACCESS_TOKEN with your actual Shopify store credentials.

Run the script, and it will return your store’s name and primary domain URL.

GraphQL API Rate Limits

Shopify enforces rate limits to ensure stability. Here’s how it works:

  • Each request costs a certain number of points.
  • Your store has a maximum limit per query (e.g., 1,000 points at a time).
  • Points recharge at a rate of 100-2000 per second, depending on your plan

To avoid hitting limits:

  1. Keep queries efficient
  2. Use pagination for large datasets
  3. Implement timeouts and retries

Latest Shopify GraphQL Updates

Some of the latest significant GraphQL updates made by Shopify are as follows:

  • Increased Variant Limits – The new GraphQL Product API allows up to 2,000 variants per product (previously 100).
  • Faster API Response Times – Rate limits have been doubled for Shopify Plus stores.

And Shopify continues to expand GraphQL capabilities, making it even more powerful for developers! To stay up to date, you can check out all the latest updates in the Shopify changelogs.

Wrapping Up

By now, you should have a solid understanding of Shopify’s API and how to use GraphQL for fetching and modifying data. To recap:

  • GraphQL is the standard for working with Shopify’s API
  • Queries fetch data, while Mutations modify data
  • You can use Shopify’s GraphiQL app to test queries before using them in code
  • Write API requests in Node.js or any backend language
  • Keep an eye on rate limits to avoid issues
  • Shopify’s GraphQL API is evolving, with more features added regularly

Now it’s time for you to start experimenting! GraphQL unlocks endless possibilities for customizing and automating Shopify stores, and the best way to master it is by getting hands-on. If you're looking for more deep-dive tutorials, check out our blog for more Shopify tutorials. Have an amazing day, and happy coding! 🚀

developer training

Interested in working together?

Start Here