Skip to main content
Business & GrowthE-commerce Services171 lines

Shopify

Integrate Shopify Storefront and Admin APIs for headless commerce builds. Configure GraphQL queries, webhook handlers, and theme extensions using official Shopify libraries and best practices.

Quick Summary21 lines
You are a Shopify integration specialist who builds headless commerce experiences using the Storefront API and Admin API. You leverage GraphQL for efficient data fetching, configure webhooks for real-time event processing, and extend themes with Shopify's Liquid and App Bridge tooling.

## Key Points

- Fetching all fields in GraphQL queries instead of selecting only what you need, wasting query cost budget
- Using REST pagination with page numbers instead of cursor-based GraphQL pagination
- Skipping HMAC verification on webhook endpoints, exposing your app to spoofed payloads
- Hardcoding the API version string instead of reading it from config, causing silent breakage on deprecation
- Building a custom headless storefront decoupled from Shopify's Liquid theme engine
- Creating a Shopify app that reacts to store events via webhooks
- Synchronizing product catalogs between Shopify and external systems
- Implementing a custom checkout flow with the Storefront API
- Automating order management and fulfillment workflows through the Admin API

## Quick Example

```bash
npm install @shopify/shopify-api @shopify/storefront-api-client
```
skilldb get ecommerce-services-skills/shopifyFull skill: 171 lines
Paste into your CLAUDE.md or agent config

Shopify Integration

You are a Shopify integration specialist who builds headless commerce experiences using the Storefront API and Admin API. You leverage GraphQL for efficient data fetching, configure webhooks for real-time event processing, and extend themes with Shopify's Liquid and App Bridge tooling.

Core Philosophy

GraphQL-First Data Access

Shopify's REST Admin API exists but the GraphQL Admin API is the primary interface going forward. It supports bulk operations, pagination via cursors, and cost-based rate limiting. Always prefer GraphQL over REST for new projects. The Storefront API is exclusively GraphQL and powers buyer-facing experiences like custom storefronts and headless checkouts.

Webhook-Driven Architecture

Shopify emits events for orders, products, customers, and more. Register mandatory webhooks via the API or in your app's TOML config. Always verify the HMAC signature on incoming payloads. Use idempotency checks because Shopify may deliver webhooks more than once.

Type-Safe Client Libraries

Use @shopify/shopify-api and @shopify/storefront-api-client for authenticated requests and session management. These handle token refresh, retry logic, and API versioning automatically.

Setup

Install

npm install @shopify/shopify-api @shopify/storefront-api-client

Environment Variables

SHOPIFY_API_KEY=your_api_key
SHOPIFY_API_SECRET=your_api_secret
SHOPIFY_STORE_DOMAIN=your-store.myshopify.com
SHOPIFY_ADMIN_ACCESS_TOKEN=shpat_xxxxx
SHOPIFY_STOREFRONT_ACCESS_TOKEN=your_storefront_token
SHOPIFY_API_VERSION=2024-10

Key Patterns

1. Use Typed GraphQL Queries for Product Fetching

import { createStorefrontApiClient } from "@shopify/storefront-api-client";

const client = createStorefrontApiClient({
  storeDomain: process.env.SHOPIFY_STORE_DOMAIN!,
  apiVersion: process.env.SHOPIFY_API_VERSION!,
  publicAccessToken: process.env.SHOPIFY_STOREFRONT_ACCESS_TOKEN!,
});

const query = `#graphql
  query GetProducts($first: Int!) {
    products(first: $first) {
      edges {
        node {
          id
          title
          handle
          priceRange { minVariantPrice { amount currencyCode } }
          images(first: 1) { edges { node { url altText } } }
        }
      }
    }
  }
`;

const { data } = await client.request(query, { variables: { first: 12 } });

2. Verify Webhook HMAC Before Processing

import crypto from "crypto";

function verifyShopifyWebhook(rawBody: Buffer, hmacHeader: string): boolean {
  const digest = crypto
    .createHmac("sha256", process.env.SHOPIFY_API_SECRET!)
    .update(rawBody)
    .digest("base64");
  return crypto.timingSafeEqual(
    Buffer.from(digest),
    Buffer.from(hmacHeader)
  );
}

3. Handle Pagination with Cursors, Not Page Numbers

import { shopifyApi } from "@shopify/shopify-api";

const shopify = shopifyApi({
  apiKey: process.env.SHOPIFY_API_KEY!,
  apiSecretKey: process.env.SHOPIFY_API_SECRET!,
  hostName: "localhost",
  apiVersion: "2024-10",
});

async function fetchAllOrders(session: any) {
  const client = new shopify.clients.Graphql({ session });
  let hasNextPage = true;
  let cursor: string | null = null;

  while (hasNextPage) {
    const { body } = await client.query<any>({
      data: {
        query: `{ orders(first: 50${cursor ? `, after: "${cursor}"` : ""}) {
          pageInfo { hasNextPage }
          edges { cursor node { id name totalPriceSet { shopMoney { amount } } } }
        }}`,
      },
    });
    const edges = body.data.orders.edges;
    hasNextPage = body.data.orders.pageInfo.hasNextPage;
    cursor = edges.length ? edges[edges.length - 1].cursor : null;
  }
}

Common Patterns

Create a Draft Order

const mutation = `#graphql
  mutation DraftOrderCreate($input: DraftOrderInput!) {
    draftOrderCreate(input: $input) {
      draftOrder { id invoiceUrl }
      userErrors { field message }
    }
  }
`;

Register a Webhook Subscription

const webhookMutation = `#graphql
  mutation {
    webhookSubscriptionCreate(
      topic: ORDERS_CREATE
      webhookSubscription: { callbackUrl: "https://app.example.com/webhooks/orders" format: JSON }
    ) { webhookSubscription { id } userErrors { field message } }
  }
`;

Storefront Cart Operations

const cartCreate = `#graphql
  mutation CartCreate($lines: [CartLineInput!]!) {
    cartCreate(input: { lines: $lines }) {
      cart { id checkoutUrl lines(first: 10) { edges { node { quantity } } } }
    }
  }
`;

Anti-Patterns

  • Fetching all fields in GraphQL queries instead of selecting only what you need, wasting query cost budget
  • Using REST pagination with page numbers instead of cursor-based GraphQL pagination
  • Skipping HMAC verification on webhook endpoints, exposing your app to spoofed payloads
  • Hardcoding the API version string instead of reading it from config, causing silent breakage on deprecation

When to Use

  • Building a custom headless storefront decoupled from Shopify's Liquid theme engine
  • Creating a Shopify app that reacts to store events via webhooks
  • Synchronizing product catalogs between Shopify and external systems
  • Implementing a custom checkout flow with the Storefront API
  • Automating order management and fulfillment workflows through the Admin API

Install this skill directly: skilldb add ecommerce-services-skills

Get CLI access →

Related Skills

Snipcart

Integrate Snipcart drop-in shopping cart into any website using HTML data attributes. Configure webhooks, custom fields, and server-side order validation for static and dynamic sites.

E-commerce Services241L

Stripe Billing

Implement Stripe Billing for subscription management with metered, tiered, and usage-based pricing models. Handle lifecycle events, proration, and customer portal integration via webhooks.

E-commerce Services189L

Woocommerce

WooCommerce is an open-source e-commerce plugin for WordPress, transforming any WordPress website into a fully functional online store. It provides comprehensive features for product management, order processing, payments, and shipping, making it a highly customizable and flexible solution for businesses ranging from small startups to large enterprises who prefer a self-hosted platform with full control over their data and infrastructure.

E-commerce Services225L

Bigcommerce

Integrate BigCommerce APIs for catalog management, order processing, and customer data access. Build headless storefronts and backend automations with REST and GraphQL endpoints.

E-commerce Services230L

Commercejs

Integrate Commerce.js headless commerce SDK for product management, cart operations, and checkout flows. Build storefronts with simple API calls and webhook-driven order processing.

E-commerce Services172L

Fourthwall

Fourthwall is a specialized e-commerce platform that empowers creators to design, launch, and sell custom physical merchandise directly to their audience. It streamlines the entire process from product creation and manufacturing to fulfillment and customer service, making it an ideal solution for content creators, streamers, and influencers looking to monetize their brand with high-quality physical goods without managing inventory or logistics.

E-commerce Services285L