Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Shopify/shopify-app-js/llms.txt

Use this file to discover all available pages before exploring further.

Quickstart

This guide will help you make your first API request to Shopify using the Admin API Client. We’ll query for a product in just a few lines of code.
This quickstart uses the @shopify/admin-api-client package, which is perfect for simple API access. If you’re building a full Shopify app with OAuth and webhooks, see the choosing a package guide.

Prerequisites

Before you begin, you’ll need:
  • A Shopify store (development or production)
  • An Admin API access token with appropriate scopes
  • Node.js 18 or higher installed
Don’t have an access token? Create a custom app in your Shopify admin under Settings > Apps and sales channels > Develop apps to get one.

Installation

Install the Admin API Client package using your preferred package manager:
npm install @shopify/admin-api-client

Your First API Request

Create a new file called index.js (or index.ts for TypeScript) and add the following code:
import {createAdminApiClient} from '@shopify/admin-api-client';

const client = createAdminApiClient({
  storeDomain: 'your-shop-name.myshopify.com',
  apiVersion: '2024-01',
  accessToken: 'your-admin-api-access-token',
});

const productQuery = `
  query ProductQuery($id: ID!) {
    product(id: $id) {
      id
      title
      handle
      status
      totalInventory
    }
  }
`;

const {data, errors} = await client.request(productQuery, {
  variables: {
    id: 'gid://shopify/Product/7608002183224',
  },
});

if (errors) {
  console.error('GraphQL errors:', errors);
} else {
  console.log('Product:', data.product);
}
1

Replace Configuration Values

Update storeDomain with your shop’s myshopify.com domain and accessToken with your Admin API access token.
2

Update the Product ID

Replace the product ID with a valid product ID from your store. You can find product IDs in your Shopify admin.
3

Run the Code

Execute your file with node index.js (or tsx index.ts for TypeScript).

Understanding the Response

The client.request() method returns a normalized response object:
{
  data?: {
    product: {
      id: string;
      title: string;
      handle: string;
      status: string;
      totalInventory: number;
    }
  },
  errors?: {
    networkStatusCode?: number;
    message?: string;
    graphQLErrors?: any[];
  },
  extensions?: Record<string, any>
}
  • data - Contains the successful API response
  • errors - Contains any network or GraphQL errors
  • extensions - Additional metadata like query cost and rate limit info

Using the REST Client

You can also use the REST Admin API client for REST endpoints:
import {createAdminRestApiClient} from '@shopify/admin-api-client';

const client = createAdminRestApiClient({
  storeDomain: 'your-shop-name.myshopify.com',
  apiVersion: '2024-01',
  accessToken: 'your-admin-api-access-token',
});

const response = await client.get('products/1234567890');

if (response.ok) {
  const product = await response.json();
  console.log('Product:', product);
}

Adding TypeScript Types

For full type safety, install the codegen preset to automatically generate types from your queries:
npm install --save-dev @shopify/api-codegen-preset
Create a .graphqlrc.ts file:
import {ApiType, shopifyApiProject} from '@shopify/api-codegen-preset';

export default {
  schema: 'https://shopify.dev/admin-graphql-direct-proxy',
  documents: ['*.ts', '!node_modules'],
  projects: {
    default: shopifyApiProject({
      apiType: ApiType.Admin,
      apiVersion: '2024-01',
      outputDir: './types',
    }),
  },
};
Add a script to your package.json:
{
  "scripts": {
    "graphql-codegen": "graphql-codegen"
  }
}
Tag your queries with #graphql and run npm run graphql-codegen to generate types automatically.

Next Steps

Explore Admin API Client

Learn about all available methods and configuration options

Try Storefront API

Build customer-facing features with the Storefront API

Build a Full App

Add OAuth, webhooks, and session management

Add Type Safety

Generate TypeScript types from your GraphQL operations

Common Issues

Authentication Error (401): Verify your access token is correct and has the required scopes for the data you’re querying.
Invalid API Version: Make sure you’re using a supported API version. The oldest stable version is recommended, but you can check available versions in the Shopify API documentation.
Rate Limiting: The client automatically handles rate limits with retries. You can configure the number of retries with the retries option (max 3).

Build docs developers (and LLMs) love