Overview
The Shopify API library provides client classes for making authenticated requests to Shopify’s Admin and Storefront APIs.
Access client classes through your configured Shopify instance:
const shopify = shopifyApi ({ /* config */ });
// Client classes
const RestClient = shopify . clients . Rest ;
const GraphqlClient = shopify . clients . Graphql ;
const StorefrontClient = shopify . clients . Storefront ;
const graphqlProxy = shopify . clients . graphqlProxy ;
GraphQL Client
The GraphQL client for making requests to the Shopify Admin GraphQL API.
Constructor
class GraphqlClient {
constructor ( params : GraphqlClientParams )
}
Parameters
The session object containing shop and access token.
Override the API version for this client. Defaults to the configured version.
request()
Makes a GraphQL request to the Admin API.
Signature
async request < T = undefined , Operation extends keyof Operations = string > (
operation : Operation ,
options ?: GraphqlQueryOptions < Operation , Operations > ,
): Promise < GraphQLClientResponse < T >>
Parameters
The GraphQL query or mutation string.
Query options: Variables to include in the operation.
Additional headers to send with the request.
Maximum number of retry attempts for throttling or server errors.
Optional AbortSignal to cancel the request.
Returns
The response data from the GraphQL query.
Example
Basic Query
With Variables
With Custom Headers and Retries
Different API Version
const client = new shopify . clients . Graphql ({ session });
const response = await client . request ( `
query getProducts {
products(first: 10) {
edges {
node {
id
title
handle
}
}
}
}
` );
console . log ( response . data . products );
REST Client
The REST client for making requests to the Shopify Admin REST API.
Constructor
class RestClient {
constructor ( params : RestClientParams )
}
Parameters
The session object containing shop and access token.
Override the API version for this client.
get()
Performs a GET request.
async get < T = any >( params : GetRequestParams ) : Promise < RestRequestReturn < T >>
post()
Performs a POST request.
async post < T = any >( params : PostRequestParams ) : Promise < RestRequestReturn < T >>
put()
Performs a PUT request.
async put < T = any >( params : PutRequestParams ) : Promise < RestRequestReturn < T >>
delete()
Performs a DELETE request.
async delete < T = any >( params : DeleteRequestParams ) : Promise < RestRequestReturn < T >>
Request Parameters
The path to the resource, relative to the API version root.
The type of data expected in the response.
DataType.JSON (default)
DataType.GraphQL
DataType.URLEncoded
data
Record<string, any> | string
The request body (required for POST/PUT).
Query parameters to send with the request.
Additional headers to send with the request.
Maximum number of retry attempts.
Returns
Example
GET Request
POST Request
PUT Request
DELETE Request
With Custom Headers
const client = new shopify . clients . Rest ({ session });
const response = await client . get ({
path: 'products' ,
query: { limit: '10' },
});
console . log ( response . body . products );
Storefront Client
The GraphQL client for making requests to the Shopify Storefront API.
Constructor
class StorefrontClient {
constructor ( params : StorefrontClientParams )
}
Parameters
The session object (can use storefront access token).
Override the API version for this client.
request()
Makes a GraphQL request to the Storefront API.
async request < T = any > (
operation : string ,
options ?: GraphqlQueryOptions
): Promise < StorefrontResponse < T >>
Example
Storefront Query
Cart Mutation
const client = new shopify . clients . Storefront ({ session });
const response = await client . request ( `
query getProduct($handle: String!) {
productByHandle(handle: $handle) {
id
title
description
priceRange {
minVariantPrice {
amount
currencyCode
}
}
}
}` ,
{
variables: { handle: 'my-product' },
}
);
console . log ( response . data . productByHandle );
GraphQL Proxy
Proxy GraphQL requests from the frontend through your backend.
Signature
type GraphqlProxy = ( params : GraphqlProxyParams ) => Promise < Response >;
Example
app . post ( '/api/graphql' , async ( req , res ) => {
const response = await shopify . clients . graphqlProxy ({
session ,
rawBody: req . body ,
rawRequest: req ,
rawResponse: res ,
});
res . status ( response . status ). send ( response . body );
});
Types
DataType
enum DataType {
JSON = 'application/json' ,
GraphQL = 'application/graphql' ,
URLEncoded = 'application/x-www-form-urlencoded' ,
}
RequestReturn
interface RequestReturn < T = unknown > {
body : T ;
headers : Headers ;
}
ClientArgs
interface ClientArgs {
session : Session ;
apiVersion ?: ApiVersion ;
retries ?: number ;
}
Error Handling
All clients throw errors for failed requests:
try {
const response = await client . request ( query );
} catch ( error ) {
if ( error instanceof ShopifyErrors . HttpResponseError ) {
console . error ( 'HTTP Error:' , error . response . status );
console . error ( 'Body:' , error . response . body );
} else if ( error instanceof ShopifyErrors . GraphqlQueryError ) {
console . error ( 'GraphQL Errors:' , error . response . errors );
}
}
Notes
All clients automatically handle rate limiting with exponential backoff when retries is specified.
The GraphQL client provides type-safe operations when used with generated types from the Shopify Admin API.
REST client methods return the full response object including headers, useful for pagination with Link headers.