Getting started overview
The Shopify Admin API allows developers to programmatically interact with and manage Shopify stores. It supports both GraphQL and REST architectural styles, with GraphQL being the primary focus for new development and features. Access to the API is included with all Shopify plans, which start from $39/month for Basic Shopify. Before making any API calls, developers need to establish a development environment, create a Shopify account, and obtain appropriate API credentials.
The core process involves selecting an app type (Custom App or Public App), generating API keys and access tokens, and then using these credentials to authenticate requests. Shopify provides SDKs in several languages, including Ruby and Node.js, to streamline development. Understanding Shopify's API rate limits is also crucial for building stable applications. This guide focuses on getting a basic request working, typically via a Custom App for initial development and testing.
Here is a quick reference for the initial setup steps:
| Step | What to do | Where |
|---|---|---|
| 1. Create Shopify Account | Sign up for a Shopify Partner account or a Shopify store trial. | Shopify free trial signup or Shopify Partner Program |
| 2. Create a Custom App | Navigate to your store's admin, go to Apps, and create a new Custom App. | Shopify Admin > Apps > Develop apps > Create an app |
| 3. Configure API Scopes | Grant the necessary API permissions (scopes) for your app. | Custom App settings > Configuration > Admin API integration > Configure Admin API scopes |
| 4. Install App & Get Token | Install the Custom App on your store to generate an Admin API access token. | Custom App details page > Install app |
| 5. Make First Request | Use the access token and API credentials to make an authenticated call. | Your preferred development environment (e.g., cURL, Postman, custom code) |
Create an account and get keys
To access the Shopify Admin API, you need either a Shopify store (development, trial, or paid) or a Shopify Partner account, which allows you to create development stores. For direct API interaction with a single store, creating a Custom App is the most straightforward approach.
Step 1: Create a Shopify Account
- If you don't have a Shopify store: Sign up for a Shopify free trial or create a Shopify Partner account to access development stores. A development store provides a sandbox environment for testing.
- If you have an existing Shopify store: Log in to your store's admin panel.
Step 2: Create a Custom App
Custom Apps are private to a specific Shopify store and are ideal for integrating with internal systems or building bespoke functionalities without making the app available publicly. They generate a permanent access token.
- From your Shopify admin, navigate to Apps.
- Click Develop apps, then Create an app.
- Give your app a name (e.g., "My First API Integration") and select an app developer.
- Click Create app.
Step 3: Configure API Scopes
API scopes define the permissions your app has within the Shopify store. For a first request, you'll need at least read access to a resource like products.
- On your new Custom App's detail page, go to Configuration.
- Under the Admin API integration section, click Configure Admin API scopes.
- Select the necessary permissions. For example, check
read_productsto fetch product data. For a complete list of available scopes, refer to the Shopify Admin API access scopes documentation. - Click Save.
Step 4: Install the App and Get Your Credentials
Installing the app will generate the Admin API access token, which is essential for authenticating your requests.
- Back on your Custom App's detail page, click Install app.
- Confirm the installation.
- Once installed, you will be presented with your Admin API access token. This token is displayed only once, so copy it immediately and store it securely. You will also see your API key and API secret key, which are less frequently used for direct calls with Custom Apps but are part of the app's identity.
Your shop's domain (e.g., your-shop-name.myshopify.com) will also be part of your API endpoint.
Your first request
With your Admin API access token and store domain, you can now make your first authenticated API call. This example demonstrates fetching a list of products using a GraphQL query, which is Shopify's recommended approach.
Example 1: Fetch products with GraphQL (cURL)
Replace {your-shop-name} with your actual Shopify store's .myshopify.com domain and {your-admin-api-access-token} with the token you securely stored from Step 4.
curl -X POST \
"https://{your-shop-name}.myshopify.com/admin/api/2024-04/graphql.json" \
-H "Content-Type: application/json" \
-H "X-Shopify-Access-Token: {your-admin-api-access-token}" \
-d '{ "query": "{ products(first: 5) { edges { node { id title createdAt } } } }" }'
This cURL command sends a GraphQL query to your store, requesting the id, title, and createdAt for the first five products. The API version (2024-04 in this example) is important; Shopify updates its Admin API quarterly, and specifying a stable version is recommended.
Example 2: Fetch products with REST (cURL)
The Admin API also supports RESTful endpoints. This example fetches all products using the REST API.
curl -X GET \
"https://{your-shop-name}.myshopify.com/admin/api/2024-04/products.json" \
-H "X-Shopify-Access-Token: {your-admin-api-access-token}"
This command retrieves product data in JSON format. The response will be an array of product objects if products exist in your store.
Common next steps
After successfully making your first call, consider these next steps to further develop your integration:
- Explore more GraphQL queries and mutations: The Shopify Admin API reference contains detailed documentation for all available GraphQL fields and operations. Use a GraphQL client like Insomnia or Postman for easier exploration.
- Implement webhooks: For real-time event handling (e.g., new order created, product updated), configure Shopify webhooks. This allows your application to react to changes on the store without constant polling. For robust webhook security, consider leveraging a third-party service for signature verification, as detailed in Stripe's webhook security guide.
- Use a Shopify API client library: To simplify development, use one of the official Shopify API client libraries for Ruby, Node.js, Python, or PHP. These libraries handle authentication, request signing, and response parsing.
- Add OAuth for public apps: If you intend to build an app that can be installed on multiple Shopify stores, you will need to implement the OAuth 2.0 flow. This involves redirecting users for authorization and exchanging an authorization code for an access token.
- Manage rate limits: Be aware of Shopify's API rate limits to prevent your application from being throttled. Implement retry logic with exponential backoff for rate-limited requests, as described in Google's API best practices for exponential backoff.
Troubleshooting the first call
Encountering issues with your first API call is common. Here's a checklist for common problems:
- Incorrect Access Token: Double-check that the
X-Shopify-Access-Tokenheader contains the exact, unexpired Admin API access token. Remember, it's shown only once upon app installation. If lost, you might need to uninstall and reinstall the custom app to generate a new one. - Incorrect API Version: Ensure the API version in your URL (e.g.,
2024-04) is current and correctly formatted. Using an outdated or invalid version can lead to errors. You can check the Shopify API release notes for current versions. - Insufficient Scopes: Verify that your Custom App has the necessary Admin API scopes configured. For example, if you're trying to fetch products but only have
read_orders, the request will fail. You can adjust scopes in your app's configuration within the Shopify admin. - Invalid Store Domain: Confirm that the
{your-shop-name}.myshopify.compart of your URL is correct and corresponds to the store where the app is installed. - Network Issues or Firewall: Ensure there are no local network issues or firewall rules blocking your outbound API requests.
- JSON Payload Errors (GraphQL): For GraphQL requests, ensure your JSON payload is syntactically correct and the query itself is valid according to the GraphQL schema.
- Rate Limiting: If you're making many requests in a short period, you might hit Shopify's rate limits. Look for
Retry-Afterheaders in the API response and implement a delay before retrying. - Typographical Errors: A simple typo in the endpoint, header name, or token can cause a request to fail. Carefully review your command or code.