Hi,
When i use Postman to do API call, it works and i get data back but when i use fetch in my Sveltekit app, i get errors: ‘[API] Invalid API key or access token (unrecognized login or wrong password)’.
I am using this format for the call https://{username}:{password}@{shop}.myshopify.com/admin/api/2021-10/graphql.json
This is my fetch
try {
const result = await fetch(import.meta.env.VITE_SHOPIFY_API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Storefront-Access-Token': import.meta.env.VITE_SHOPIFY_STOREFRONT_API_TOKEN
},
body: JSON.stringify({ query, variables })
}).then((res) => res.json());
if (result.errors) {
console.log({ errors: result.errors });
} else if (!result || !result.data) {
console.log({ result });
return 'No results found.';
}
console.log(result);
return result.data;
} catch (error) {
console.log(error);
}