Rohan Yeole - HomepageRohan Yeole

What is Shopify GraphQL API and Why Should You Use It?

By Rohan Yeole

Introduction

If you're building apps for Shopify and still using the REST Admin API, it's time for a change. As of October 1, 2024, Shopify deprecated its REST Admin API, officially making GraphQL the only supported option for new apps. 

This change caught many developers off guard, especially those with legacy scripts and integrations.
In this guide, you'll learn how to adapt quickly by using Python to connect to Shopify via GraphQL — based on a real-world scenario.

Why Shopify Switched to GraphQL

Shopify's shift to GraphQL was inevitable. REST APIs are rigid and inefficient when dealing with complex data models and nested structures. GraphQL solves that with:

  • Precise data queries
  • A single, flexible endpoint
  • Fewer requests, less bandwidth
  • "On October 1, 2024, all apps using the REST Admin API became legacy and stopped working."

Related: REST vs GraphQL for Shopify – Pros and Cons

A Real-World Scenario: Price Sync Script Fails

In early October 2024, a client requested updates to a Shopify store that sold European machinery in the U.S. My old script — built to auto-update EUR to USD product prices via REST — stopped working.

Turns out, the REST API was deprecated. My only choice was to learn GraphQL — fast. Hours of trial and error later, this guide was born.

What is GraphQL?

GraphQL is a modern query language for APIs that lets you:

  • Ask only for the data you need

  • Use a single endpoint for all queries

  • Avoid over-fetching or under-fetching data

You still use HTTP POST/GET requests, but the structure and response are JSON-defined.

Learn more:graphql.org

Step 1: App Setup & Access

To use GraphQL, you must:

  1. Be approved as an app developer (Shopify Partner or Collaborator).

  2. Get access via a Collaborator Request Code.

  3. Create a Custom App under Apps and Sales Channels > Develop Apps.

Once the app is created:

  • Go to the API Credentials tab

  • Click Configure Admin API scopes

  • Assign required scopes:

write_content, read_content,
read_customers,
read_orders,
write_products, read_products,
write_inventory, read_inventory,
read_analytics
Save, then Install App to generate the access token.

Step 2: Get Your API Token and Endpoint

From the API Credentials tab:

  • Copy your Admin API access tokenAPI_TOKEN

  • Your store name (from admin URL): STORE_NAME

  • API version (format: YYYY-MM): GRAPHQL_VER

  • Endpoint:

https://STORE_NAME.myshopify.com/admin/api/GRAPHQL_VER/graphql.json

Step 3: Your First Query with Python (requests)

Here’s how to fetch products using plain HTTP POST with Python:

Step 3: Your First Query with Python (requests)

import json
import requests

API_TOKEN = 'shpat_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
STORE_NAME = "my-store-name"
GRAPHQL_VER = "2024-10"
GRAPHQL_ENDPOINT = f"https://{STORE_NAME}.myshopify.com/admin/api/{GRAPHQL_VER}/graphql.json"

headers = {
'Content-Type': 'application/graphql',
'X-Shopify-Access-Token': API_TOKEN,
}

products_query = '''
query {
products(first: 5) {
edges {
node {
id
handle
}
}
pageInfo {
hasNextPage
}
}
}
'''

response = requests.post(GRAPHQL_ENDPOINT, data=products_query, headers=headers)
print(json.dumps(response.json(), indent=2))

Note: Use 'application/graphql' not 'application/json' in headers.

Step 4: Use the Shopify Python SDK (Optional)

Prefer using an SDK? Here's how:

import shopify

products_query = '''
    query {
        products(first: 5) {
            edges {
                node {
                    id
                    handle
                }
            }
            pageInfo {
                hasNextPage
            }
        }
    }
'''
with shopify.Session.temp(GRAPHQL_ENDPOINT, GRAPHQL_VER, API_TOKEN):

    result = shopify.GraphQL().execute(products_query)
    print(result)

Reference:Shopify Python SDK GitHub

Conclusion

Shopify GraphQL may look intimidating at first, but it's powerful once you understand the basics. If your REST-based Shopify scripts are broken, this guide should help you quickly adapt.

If you found this tutorial useful, consider leaving a comment or sharing it with fellow developers!

Must Read