CORS blocking API request

mentoir
New Member
1 0 0

We recently had an implementation done on our shop that makes a request to the Shopify API to populate the collections page. It's an try-on app, so they customized the collections page to pull product photos and show a try-on for each product.

However, we're running into CORS errors with the calls they made to our Admin API, and looking on the forums the solutions are very scattered and convoluted.

Errors:

Access to XMLHttpRequest at 'https://[domain].myshopify.com/admin/api/2021-01/[json]' (redirected from 'https://[domain].com/admin/api/2021-01/[json]') from origin 'https://[domain].com' 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.

GET https://[domain].myshopify.com/admin/api/2021-01/[json] net::ERR_FAILED

 

This is the call:

function getCollections() {
$.get('/admin/api/2021-01/[json]', (result) => {
storeOriginalSunglasses(result?.products);
}).then($.get('/admin/api/2021-01/[json]', (result) => {
storeOriginalOpticals(result?.products);
})).then(() => {
getFrontalFrameSunglasses(getScanIdCookie());
}).then(() => {
getFrontalFrameOpticals(getScanIdCookie());
}).then(() => { getStoredFrontals() });
}

I assume the issue is the mismatch from the domain redirection, but what's the best current way to resolve this?

Thank you for any help!

0 Likes