Integrations

Use Shopify with Prismic

Learn how to build websites with Shopify and Prismic.

This guide shows how to integrate Shopify with Prismic to display products and collections in your content.

You’ll learn two approaches:

  • Using Prismic’s built-in Shopify integration to select individual products.
  • Creating a custom integration catalog using an API endpoint.

Both methods allow content writers to choose Shopify data directly from the Prismic editor while giving developers full control over how the data is displayed.

Prerequisites

Before you begin, you’ll need to set up Shopify API access for your store.

  • Create a Shopify custom app

    Shopify requires custom apps for API access. Navigate to your Shopify admin and go to Settings > Apps and sales channels > Develop apps and click Create an app.

    Use the following values when creating your app:

    FieldValue
    App Name”Prismic Integration” (or your preferred name)
    Admin API access scopesProducts: Read access
    Storefront API access scopesProducts: Read access

    Click Create app and then Install app to finish setup.

    Learn more about Shopify custom apps

  • Set up environment variables

    After creating your app, save your Storefront API credentials as environment variables in a .env file:

    .env
    # Your Shopify store domain (without https://)
    SHOPIFY_STORE_DOMAIN=your-store-name.myshopify.com
    
    # Your Shopify Storefront API access token
    SHOPIFY_STOREFRONT_ACCESS_TOKEN=your_storefront_token_here

Select products in Prismic

Follow these steps when content writers need to select an individual product from a Shopify store.

  • Create a Shopify integration catalog

    Prismic has a native integration to select products from a Shopify using an integration field.

    To begin, follow the linked guide to create a Shopify integration field catalog.

    Learn how to create a Shopify integration catalog

  • Add a product field to a content model

    After creating the catalog, connect it to an integration field in a slice, page type, or custom type depending on where you need the product data.

    Learn how to add an integration field

  • Display the product

    The integration field provides basic product metadata. In some cases, content from the metadata is sufficient.

    import { isFilled } from "@prismicio/client";
    
    {
      isFilled.integration(slice.primary.product) && (
        <div>
          <h3>{slice.primary.product.title}</h3>
          <p>{slice.primary.product.vendor}</p>
          <div
            dangerouslySetInnerHTML={{ __html: slice.primary.product.body_html }}
          />
        </div>
      );
    }

    If you need additional product data, use Shopify’s Storefront API client.

    npm install @shopify/storefront-api-client

    This example shows how to fetch a product’s title and isGiftCard properties using the Shopify Storefront API client.

    src/slices/FeaturedProduct/index.tsx

    You can type your Shopify GraphQL queries with GraphQL Codegen.

  • Add a product to a page

    Test your new field by selecting a product in a page. If everything was set up correctly, you should see the product displayed on your page.

Product metadata

The product metadata matches what is provided by Shopify’s REST Admin API.

See the Product resource reference

Here is an example of what an integration field containing a Shopify product looks like from the Content API:

Select product collections in Prismic

Follow these steps when content writers need to select an individual product collection from a Shopify store. The collection’s products can be displayed from the website.

  • Add an integration endpoint to your website

    Making product collections available to integration fields requires a custom integration catalog.

    To begin, install Shopify’s Storefront API client.

    npm install @shopify/storefront-api-client

    Next, add an API endpoint that returns your store’s collections.

    src/app/api/collections/route.ts
  • Deploy your website

    Your API endpoint needs to be deployed and accessible by Prismic.

    Follow the deployment instructions for Next.js, Nuxt, or SvelteKit before continuing. Remember to add your environment variables to your deployment.

    You’ll use your website’s deployed URL in the next step.

  • Create an integration catalog

    Follow the linked guide to connect the API endpoint to a custom integration catalog.

    Learn how to create a custom integration catalog

    Use the following field values when creating the catalog:

    FieldDescription
    Catalog Name”Product Collections”
    Description”Product collections from the Shopify store.”
    EndpointThe full public URL to the API endpoint (e.g. https://example.com/api/collections)
    Access TokenAn optional secret string used to authenticate API calls.
  • Add a collection field to a content model

    After creating the catalog, connect it to an integration field in a slice, page type, or custom type depending on where you need the product data.

    Learn how to add an integration field

  • Display the collection

    The integration field provides collection metadata. In some cases, content from the metadata is sufficient.

    import { isFilled } from "@prismicio/client";
    
    {
      isFilled.integration(slice.primary.collection) && (
        <div>
          <h3>{slice.primary.collection.title}</h3>
          <p>{slice.primary.collection.description}</p>
        </div>
      );
    }

    If you need to fetch the collection’s products, use Shopify’s Storefront API client.

    This example shows how to fetch a collection’s products using the Shopify Storefront API client.

    src/slices/FeaturedCollection/index.tsx
  • Add a collection to a page

    Test your new field by selecting a product collection in a page. If everything was set up correctly, you should see the collection displayed on your page.

Product collection metadata

The collection data returned by Prismic’s Content API includes the following fields:

property
Description
Default
id
string

The collection’s unique identifier from Shopify

handle
string

The collection’s URL handle (used for Storefront API queries)

title
string
The collection’s display name
description
string

The collection’s description text

image
object

The collection’s image object containing the URL

Here is an example of what an integration field containing a Shopify collection looks like from the Content API:

Was this page helpful?