Shopify- Getting CORS error While calling GraphQl from store frontend

I am trying to implement something. In which I am using GraphQl to read the Product data front store frontend. But while API call I am getting a CORS error. Error message:- from origin 'store URL' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.' I tried to check but I found nothing that helps. Code:- const response = await fetch(https://test-store.myshopify.com/admin/api/2023-04/graphql.json, { method: 'POST', headers: { 'Content-Type': 'application/graphql', 'X-Shopify-Access-Token': "admin_token", }, body: JSON.stringify({ query: { product(id: "${productId}") { variants(first: 10) { edges { node { id inventoryItem { id } } } } } }, }), });

Comment (0)

You’ll be in good company