Skip to main content

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

session
Session
required
The session object containing shop and access token.
apiVersion
ApiVersion
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

operation
string
required
The GraphQL query or mutation string.
options
GraphqlQueryOptions
Query options:

Returns

data
T
The response data from the GraphQL query.
headers
Headers
Response headers.
errors
GraphQLError[]
GraphQL errors (if any).

Example

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

session
Session
required
The session object containing shop and access token.
apiVersion
ApiVersion
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

path
string
required
The path to the resource, relative to the API version root.
type
DataType
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
SearchParams
Query parameters to send with the request.
extraHeaders
HeaderParams
Additional headers to send with the request.
tries
number
Maximum number of retry attempts.

Returns

body
T
The response body.
headers
Headers
The response headers.

Example

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

session
Session
required
The session object (can use storefront access token).
apiVersion
ApiVersion
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

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.

Build docs developers (and LLMs) love