Walkthrough on integrating e-commerce with Astro and Shopify

A step-by-step guide on how to integrate an e-commerce platform with Astro and Shopify, including code snippets.

Tue Jun 10 2025 00:00:00 GMT+0000 (Coordinated Universal Time)

Shopify’s documentation can be frustrating. With the rise of AI and machine learning, why isn’t there a way to download comprehensive documentation for personal LLMs to enable Socratic learning? Instead, we’re stuck with scattered, incomplete resources. Shopify reference docs

Here’s how I integrated Shopify with Astro for a headless e-commerce solution:

  1. Create a Shopify Partner account Navigate to partner.shopify.com since it lets you create as many development stores for testing as you need.

  2. Make a test directory and initialize it Start by creating a new directory for your project and navigating into it:

    mkdir my-test-store
    cd my-test-store
  3. Install Shopify CLI I prefer using the CLI to avoid searching for links or buttons:

npm i -g @shopify/cli@latest
  1. Choose your app type At this point, you have two options for Shopify app development:
  • Hydrogen app:
shopify hydrogen init

Follow the Hydrogen documentation.

  • Remix app:
shopify app init

Follow the Remix documentation.

Here’s a comparison of Hydrogen vs. Remix:

Feature/AspectHydrogenRemix
PurposeShopify-specific custom storefrontsGeneral-purpose web applications
Pre-Built ComponentsIncludes Shopify-specific componentsNo pre-built Shopify components
Integration with ShopifyDeeply integrated with Shopify APIs and ecosystemCan integrate with Shopify APIs, but not specific
HostingOptimized for Shopify’s Oxygen hostingHosting-agnostic (can be deployed anywhere)
FlexibilityOpinionated framework tailored for e-commerceUnopinionated and flexible
Use CaseBest for Shopify storefrontsBest for general web applications, including storefronts

Both options don’t fit my goal of creating a separate shop component for my Astro website. Instead, I followed Shopify’s Headless documentation and documented my process for future reference.

Pro Tip: If you need a website, go the Hydrogen route. Two commands and you’ve got a store up and running. shopify hydrogen

  1. Create a development store From your Partner dashboard, create a development store where you can test features.

  2. Log into the store Access your store via the Partner dashboard, which opens the admin panel (e.g., admin.shopify.com/<store_id>).

  3. Create a custom app Go to “Develop app” → “Create custom app” → “Install app.” This process generates an API token for accessing Shopify’s ecosystem.

  4. Test the Storefront API Write a Node.js app to test your API token and fetch product data. Example code:

import dotenv from 'dotenv';
dotenv.config();

const SHOPIFY_STORE_DOMAIN = '<your-store-name>.myshopify.com';
const SHOPIFY_ENDPOINT = `https://${SHOPIFY_STORE_DOMAIN}/api/2024-01/graphql.json`;
const SHOPIFY_STOREFRONT_ACCESS_TOKEN = '<your-access-token>';

const query = `
  query getProducts($first: Int!) {
    products(first: $first) {
      edges {
        node {
          id
          title
          description
          handle
          images(first: 1) {
            edges {
              node {
                url
                altText
              }
            }
          }
          variants(first: 1) {
            edges {
              node {
                id
                title
                price {
                  amount
                  currencyCode
                }
              }
            }
          }
        }
      }
    }
  }
`;

async function testShopifyAPI() {
  try {
    const response = await fetch(SHOPIFY_ENDPOINT, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-Shopify-Storefront-Access-Token': SHOPIFY_STOREFRONT_ACCESS_TOKEN,
      },
      body: JSON.stringify({
        query: query,
        variables: { first: 5 },
      }),
    });

    const data = await response.json();
    console.log('Products:', data.data.products.edges);
  } catch (error) {
    console.error('Error:', error);
  }
}

testShopifyAPI();
  1. Populate the dev store Use Shopify’s built-in option to populate your dev store with random products, customers, and orders.

  2. Map API results to your Astro site Convert the API response (data) into JSON for Astro to consume. Example result: shopify headless

For a quick solution, use Hydrogen for a Shopify storefront. For headless setup, Shopify’s Storefront API (headless but you need to develop a custom app by Shopify’s terms) is the way to go. It abstracts the inventory in a database and tracks everything else. Will do another sprint on auth and login and managing it on a personal site soon.