Shopify Data Fetch Error - URL not Defined in .env.local

9 replies
Last updated: Jun 30, 2022
Anyone knows how to debug this? I'm getting this when trying to fetch shopify data
Jun 30, 2022, 10:31 AM
I set it up like this
import Client from "shopify-buy";
export const shopifyClient = Client.buildClient({
  storefrontAccessToken: process.env.NEXT_PUBLIC_SHOPIFY_STORE_FRONT_ACCESS_TOKEN,
  domain: process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN,
});


export const parseShopifyResponse = (response) =>  JSON.parse(JSON.stringify(response));
Jun 30, 2022, 10:32 AM
and then try to grab it in a index.js
import { Product, Cart, Navbar, Layout, Collection } from "../components";
import { client } from "../lib/client";
import { shopifyClient, parseShopifyResponse } from '../lib/shopify'

const Home = ({ products }) => {
  return (
    <>
      <Product product={products} />
      {console.log(products)}
    </>
  );
};

export const getServerSideProps = async () => {
  // Fetch all the products
  const products = await shopifyClient.product.fetchAll();


  return {
   props: {
    products: parseShopifyResponse(products),
  },
 };
};

export default Home;
Jun 30, 2022, 10:32 AM
That should be relatively easy to debug: checking the URL in the error, you can see the domain is undefined.
Jun 30, 2022, 10:34 AM
well yes it does say that but in my .env.local I really did define my URL
Jun 30, 2022, 10:37 AM
You could try logging
NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN
before you use it?
Jun 30, 2022, 10:39 AM
oh I changed the url abit now it works
Jun 30, 2022, 10:39 AM
it's hard to understand why sometimes you need https and sometimes you dont in this case I just need the plane url like store.com
Jun 30, 2022, 10:40 AM
We fixed it thanks !
Jun 30, 2022, 10:40 AM
Nice. πŸ™‚
Jun 30, 2022, 10:40 AM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.