btahir / next-shopify-starter

Nextjs + Tailwind CSS + Shopify Starter
https://doggystickers.vercel.app
MIT License
777 stars 261 forks source link

Could not fetch products #1

Closed NitsanCohen770 closed 3 years ago

NitsanCohen770 commented 3 years ago

Hi! First of all thanks a lot for sharing your amazing project. I am having some hard time connecting shopify to the app, this is the error I am getting; Error: Could not fetch products! at callShopify (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/.next/server/pages/index.js:294:11) at processTicksAndRejections (node:internal/process/task_queues:94:5) at async getAllProductsInCollection (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/.next/server/pages/index.js:335:20) at async getStaticProps (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/.next/server/pages/index.js:3672:20) at async renderToHTML (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/render.js:28:1737) at async /home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/next-server.js:112:97 at async __wrapper (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/lib/coalesced-function.js:1:330) wait - compiling... event - compiled successfully https://adri-bike.myshopify.com/ Error: Could not fetch products! at callShopify (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/.next/server/pages/index.js:295:11) at processTicksAndRejections (node:internal/process/task_queues:94:5) at async getAllProductsInCollection (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/.next/server/pages/index.js:336:20) at async getStaticProps (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/.next/server/pages/index.js:3673:20) at async renderToHTML (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/render.js:28:1737) at async /home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/next-server.js:112:97 at async __wrapper (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/lib/coalesced-function.js:1:330) at async DevServer.renderToHTMLWithComponents (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/next-server.js:137:387) at async DevServer.renderToHTML (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/next-server.js:138:522) at async DevServer.renderToHTML (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/server/next-dev-server.js:35:578) at async DevServer.render (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/next-server.js:75:236) at async Object.fn (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/next-server.js:59:580) at async Router.execute (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/router.js:25:67) at async DevServer.run (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/next-server.js:69:1042) at async DevServer.handleRequest (/home/nitsancohen/Coding/next/next-shop/next-shopify-starter/node_modules/next/dist/next-server/server/next-server.js:34:504)

I did enter all the details in the env.local file. I am new with next and shopify so please help me :)

btahir commented 3 years ago

Most likely an error with credentials(make sure your API keys are correct) or your store is not setup properly (not on a paid plan).

maziano commented 3 years ago

Was able to fix it :).. First you need to create a .env.local file, add your "token" (located at the bottom of the app) and NOT API key. Second, make sure that shopify collection is written as a handle (no spacing between multiple text- for example "dog snickers" collection will be written as "dog-snickers" in the file and not the other way around)- so to do this go to collection and click edit website seo (located down) and copy the collection handle from there (at the back of the url) to the .env.local file . Reading the shopify.json, products are only retrieved based on collection handle and not "collection name" (which is the same but with dash between spaces). If you like also change the API version from 2021-04 (which is the most recent) to 2021 -01 (which is the version this repo was written (might not make any effect but worth the try). Hope this helps