Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching products returns outdated data depending on API Version #976

Closed
4 tasks done
dvub opened this issue Dec 27, 2023 · 2 comments
Closed
4 tasks done

Fetching products returns outdated data depending on API Version #976

dvub opened this issue Dec 27, 2023 · 2 comments

Comments

@dvub
Copy link

dvub commented Dec 27, 2023

Bug details

Describe the bug

When I make a request with the SDK, I'm essentially always getting stale data. For some reason, jumping versions -- from 2023-10 to 2023-07 -- sometimes has fixed the issue (would need to test this more). The only consistently working hack I've found is to just reinstall the app.

To Reproduce
Steps to reproduce the behaviour:

  1. Create a development store on shopify and follow the conventional steps to create a new app. Go through the usual configuration and get the domain and storefront token.
  2. Create a nextjs app: npx create-next-app@latest - Make sure to create an app directory.
  3. Add the SDK: npm i shopify-buy
  4. Create a .env file with the appropriate SHOPIFY_STOREFRONT_TOKEN, SHOPIFY_DOMAIN, and SHOPIFY_API_VERSION variables.
  5. Under the app directory, create the directory/file: api/products/route.ts with this code:
import Client from 'shopify-buy';
export async function GET(request: Request) {
	const client = Client.buildClient({
		storefrontAccessToken: process.env.SHOPIFY_STOREFRONT_TOKEN!,
		domain: process.env.SHOPIFY_DOMAIN!,
		apiVersion: process.env.SHOPIFY_API_VERSION!, //2023-10 ?
	});

	const data = await client.product.fetchAll();
	console.log(data.length);
	return new Response(JSON.stringify(data));
}
  1. Make a request to the route, optionally within the app (I used axios and SWR - you'll need to install these if you do it this way)
  2. Add a product, make a new request, and compare the number of items. In my case, the number doesn't update when updating product information.

Expected behavior

When adding a new product through the shopify admin, the API route should reflect the updated data.

Environment (please complete the following information):

  • OS: Arch Linux (6.6.8-arch1-1)
  • Browser: Brave (Chromium)
  • SDK Version 2.21.1

Additional context
n/a
Bug Report Checklist

  • I have read and agree to the CODE_OF_CONDUCT.md
  • I have read the CONTRIBUTING.md guidelines.
  • I have provided a detailed description of the bug, including code samples, and/or network data.
  • I have provided information about my development environment, including SDK version.
@dvub dvub closed this as completed Dec 28, 2023
@dvub
Copy link
Author

dvub commented Dec 28, 2023

I realized this is an issue with nextjs and route handler caching. Closing this issue.

@JRDMIII
Copy link

JRDMIII commented Jun 19, 2024

Would you mind letting me know what you did to fix it regarding nextjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants