Expert needed to resolve CORS error accessing Admin API

cocoandbreezy
New Member
3 0 0

We recently had an implementation done on our shop that makes a request to our Admin API to populate the collections page. The implementation was a glasses try-on app, so they customized the collections page to pull product photos and show a try-on for each pair of glasses.

However, while testing we ran into CORS errors with the calls they made to our Admin API. The product images are not showing up at all. The API calls seem to be accurate, but are being blocked by CORS. The try-on app has other Shopify clients who are able to use this feature, so we know there must be a simple solution.

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() });
}

 

Please only reach out if you are familiar with this kind of error. Note that the error is not present in our live site (https://cocoandbreezy.com/) but we can send a preview if you would like to see the version with the error.

Thank you!

0 Likes
HymnZ
Shopify Partner
388 4 49

Rookie mistake.

Shopify's REST API is an authenticated API meaning you cannot make the calls from a browser. You have to route it through an app.

However, what you are trying to implement can be achieved easily by using Shopify JavaScript Buy SDK

My speciality lies in making Shopify work for your requirements, not the other way round. HMU on email: hymnz@outlook.com or on skype: hymnzzy

If you like my work, consider supporting me :) https://www.buymeacoffee.com/hymnz
0 Likes
mariaj0
Shopify Partner
52 1 1

Hello,

I can help you in resolving the issue.

Please share some details so that I can review.

You can also reach me over skype: live:.cid.e0656fece75456e6 or email me at maria@cisinlabs.com for further discussion.

Kind Regards

Maria

+13478093381

0 Likes
Jennifer20
Navigator
610 18 22

Hi @cocoandbreezy

I hope you're keeping great!

I would be happy to work with you. Please give me a suitable time to discuss your requirements.

Also, add me over Skype id- live:jennifer.wcoast or Email- sales@wreximinfotech.com

I look forward to your response!

Stay Well

Thanks!

0 Likes
Nicole_C
Shopify Partner
43 1 0

Hello,

I can help you out with this.

Personal message sent, please check

Thanks,

Nicole

0 Likes