App reviews, troubleshooting, and recommendations
Hi, is there anybody who can helps me with the fetch request to shopify API? I would like to get all products and use them for product select in form. I dont really know whats wrong with it.
I read docs and i think it should work this way, but i am getting console errors and cant get response.
I had created private app because access and tokens, but still cant find the solution.
Hello @Pablo213
Your Api code is correct, you face this issue because you do not use a header to access JSON data.
Because shopify is for security purposes not allow third-party access to data.
You need to paste the below code into your code file on the above.
header("Access-Control-Allow-Origin: *");
Do you mean add this code to headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token':"fb70610e4eb8cbd8c14557560e8a190a-1681990272", 'Access-Control-Allow-Origin': '*',
}
this way? Thats what i found on the internet
I have it this way now, but still doesnt work
I think you used Node language to create an app.
I have an idea about PHP language.
Could you please check how to apply the header for Allow Access control origin *?
Idk man, but i am doing it with javascript now and still doesnt work..
fetch('https://your-shop-name.myshopify.com/admin/api/2023-04/products.json', {
headers: {
'Access-Control-Allow-Origin': '*'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
I use it that way exactly, but where is the problem? In headers i have an extra access- token which i should use i guess?
When I search it's on Google
// Set the Access-Control-Allow-Origin header to *
response.setHeader("Access-Control-Allow-Origin", "*");
// Define the headers for your API request
const headers = {
'X-Shopify-Access-Token': 'your-access-token-here',
'Content-Type': 'application/json'
};
// Make a GET request to a Shopify API endpoint
fetch('https://your-shop-name.myshopify.com/admin/api/2023-04/your-resource.json', { headers })
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
Am i doing anything wrong besides writing differently?
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023