SDKs overview
The Shopify Admin API provides programmatic access to store data and functionality, enabling developers to build applications that extend and automate Shopify stores. To facilitate this interaction, Shopify offers a suite of official SDKs and supports a vibrant community contributing additional libraries. These SDKs abstract away the complexities of HTTP requests, JSON parsing, and OAuth 2.0 authentication, allowing developers to focus on application logic. The API itself is GraphQL-first, with REST equivalents available for many operations, and the SDKs reflect this dual approach, offering clients for both paradigms.
Using an SDK or library can streamline development by providing:
- Simplified API calls: Methods that map directly to API endpoints.
- Authentication handling: Built-in support for OAuth 2.0 flows, including token acquisition and refresh.
- Error handling: Consistent mechanisms for identifying and responding to API errors.
- Type safety (for some languages): Enhanced developer experience through type hints and auto-completion.
- Rate limit management: Some SDKs offer basic mechanisms to respect API rate limits.
Official SDKs by language
Shopify maintains official SDKs for several popular programming languages, designed to provide a robust and well-supported interface to the Admin API. These SDKs are actively developed and documented on the official Shopify Developer documentation. The choice of SDK often depends on the developer's preferred language and existing technology stack.
The table below outlines the primary official SDKs, their typical package names, and their installation methods:
| Language | Package/Library Name | Install Command | Maturity |
|---|---|---|---|
| Ruby | shopify_api |
gem install shopify_api |
Stable |
| Node.js | @shopify/shopify-api |
npm install @shopify/shopify-api |
Stable |
| PHP | shopify/shopify-api |
composer require shopify/shopify-api |
Stable |
| Python | shopify-api |
pip install ShopifyAPI |
Stable |
| React | @shopify/app-bridge |
npm install @shopify/app-bridge |
Stable (for UI extensions) |
Installation
Installing a Shopify Admin API SDK typically follows the standard package management practices for each respective language. Before installation, ensure your development environment has the necessary language runtime and package manager installed (e.g., RubyGems for Ruby, npm/yarn for Node.js, Composer for PHP, pip for Python).
Ruby
The Ruby SDK is a Ruby Gem. You can install it using the gem command:
gem install shopify_api
To include it in your project's dependencies, add gem 'shopify_api' to your Gemfile and run bundle install.
Node.js
The Node.js SDK is available via npm. Use either npm or yarn to install:
npm install @shopify/shopify-api
# OR
yarn add @shopify/shopify-api
PHP
The PHP SDK is managed with Composer. Add it to your project's dependencies:
composer require shopify/shopify-api
Python
The Python SDK is distributed via PyPI. Install it using pip:
pip install ShopifyAPI
Quickstart example
This quickstart example demonstrates how to initialize the Shopify Admin API client and make a simple request using the Node.js SDK. This example assumes you have already obtained the necessary API credentials (SHOPIFY_API_KEY, SHOPIFY_API_SECRET, SHOPIFY_APP_URL) and a valid access token for a Shopify store (SHOPIFY_ACCESS_TOKEN, SHOPIFY_SHOP_DOMAIN) through the OAuth authorization flow. For a complete guide on setting up OAuth, refer to the Shopify authentication documentation.
First, ensure you have the Node.js SDK installed:
npm install @shopify/shopify-api dotenv
Then, create a .env file in your project root with your credentials:
SHOPIFY_API_KEY=shpat_YOUR_API_KEY
SHOPIFY_API_SECRET=shpss_YOUR_API_SECRET
SHOPIFY_SHOP_DOMAIN=your-shop-name.myshopify.com
SHOPIFY_ACCESS_TOKEN=shpat_YOUR_ACCESS_TOKEN
Now, create an application file (e.g., index.js) to initialize the client and fetch data:
require('dotenv').config();
const { shopifyApi, LATEST_API_VERSION } = require('@shopify/shopify-api');
// Basic initialization with API credentials
const shopify = shopifyApi({
apiKey: process.env.SHOPIFY_API_KEY,
apiSecretKey: process.env.SHOPIFY_API_SECRET,
scopes: ['read_products', 'write_products'], // Scopes granted during OAuth
hostName: process.env.SHOPIFY_APP_URL || 'your-app-domain.com',
is => process.env.SHOPIFY_IS_EMBEDDED_APP === 'true' ? true : false,
apiVersion: LATEST_API_VERSION,
is : process.env.SHOPIFY_IS_PRIVATE_APP === 'true' ? true : false,
});
async function getProducts() {
try {
// Create a client for the specific shop and access token
const client = new shopify.clients.Graphql({
session: {
shop: process.env.SHOPIFY_SHOP_DOMAIN,
accessToken: process.env.SHOPIFY_ACCESS_TOKEN,
isOnline: true, // Indicates an online token, not an offline token
scope: 'read_products,write_products',
}
});
// GraphQL query to fetch the first 5 products
const products = await client.query({
data: `{
products(first: 5) {
edges {
node {
id
title
vendor
}
}
}
}`,
});
console.log('Fetched Products:');
products.body.data.products.edges.forEach(edge => {
console.log(`- ${edge.node.title} by ${edge.node.vendor} (ID: ${edge.node.id})`);
});
} catch (error) {
console.error('Error fetching products:', error);
if (error.response) {
console.error('API Error Response:', error.response.errors || error.response.data);
}
}
}
getProducts();
Run the script:
node index.js
This script initializes the Shopify API client with your credentials, creates a GraphQL client for a specific store session, and then executes a GraphQL query to retrieve the titles, vendors, and IDs of the first five products. The output will display these product details in your console.
Community libraries
Beyond the official offerings, the Shopify developer community has created various libraries and tools that can assist with Admin API interactions. These community-driven projects often cater to specific use cases, provide bindings for languages not officially supported, or offer alternative approaches to common tasks. While not officially maintained by Shopify, many are open-source and widely used.
Examples of community contributions include:
- Go/Golang: Several open-source Go clients exist for interacting with the Shopify API, often leveraging the official GraphQL schema. Developers can search GitHub for Shopify API clients to find these.
- Java: While an official Java SDK isn't paramount, community libraries and general-purpose HTTP clients (like Apache HttpClient or OkHttp) can be used to construct requests to the Admin API.
- CLI Tools: Various command-line interface tools built by the community simplify tasks like theme development, app deployment, and data migration.
When considering a community library, it is advisable to evaluate its active maintenance, documentation quality, and community support. The official Shopify developer forums and community channels are good resources for discovering and discussing these alternative tools.