We are using the Storefront API to build a PWA. Everything has been smooth sailing until we specify a version in the request.
Here is a raw example of what is working:
$.ajax({
type : 'POST',
url : 'https://mystore.myshopify.com/api/graphql',
headers: {
'X-Shopify-Storefront-Access-Token': 'tokenhere',
'Content-Type': 'application/json'
},
data: 'query { shop { name } }',
success: function(res) {
console.log(res)
},
error: function(status) {
console.log(status)
}
});
Once we specify the version, like below, it fails.
$.ajax({
type : 'POST',
url : 'https://mystore.myshopify.com/api/2020-04/graphql',
headers: {
'X-Shopify-Storefront-Access-Token': 'tokenhere',
'Content-Type': 'application/json'
},
data: 'query { shop { name } }',
success: function(res) {
console.log(res)
},
error: function(status) {
console.log(status)
}
});
Response:
Access to XMLHttpRequest at 'https://mystore.myshopify.com/api/2020-04/graphql' from origin 'https://community.shopify.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Any support is much appreciated.
Thanks,
Tristan.