REST Admin API on custom domain triggers the CORS error

Bhavik
Shopify Partner
2 0 0

Hello,

 

I have created a private APP from Shopify admin panel in the dev store. The example URL format for API is like:
https://{apikey}:{password}@{hostname}/admin/api/{version}/{resource}.json

 

I am calling a product detail API in the dev store front page using ajax call. for example: https://{apikey}:{password}@{hostname}/admin/api/2020-01/products/4397844037750.json. It's working and providing the product detail.

 

Similarly, I have a private APP created for a live store as well. Calling product detail API in live store(with a custom domain) front page triggers the CORS error:

 

Access to XMLHttpRequest at 'https://[mylivestorename].myshopify.com/admin/api/2020-04/products/4397844037750.json' (redirected from 'https://{apikey}:{password}@{hostname}/admin/api/2020-04/products/4397844037750.json') from origin 'https://www.[mycustomdomainname].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.

 

cors.png

 

Is there any configuration or settings required at the server side to resolve this CORS issue with the custom domain?

 

Please let me know if anything unclear to understand the issue.

Regards

0 Likes
gseilei
Shopify Expert
235 28 39

Hi @Bhavik , check this post: https://community.shopify.com/c/Shopify-APIs-SDKs/Private-app-CORS-error/td-p/517991, I am sure you will find answers in there.

 

Let me know if that helps!

We help you achieve your Goals! Visit us on: Webmefy.com
0 Likes
achieveapplabs
Shopify Partner
497 39 78

Hi @Bhavik ,

 

Try adding this to your response header:

 

'Access-Control-Allow-Origin': '*'

Regards,

 

Sam

 

 

Use Approovly to create and track order approvals | Looking for more Shopify apps? achieveapplabs.com/#apps
Nora_and_Rose
New Member
1 0 0

Could you please explain how to add the Access-Control-Allow-Origin to the response header in Shopify? Where to find the settings to do it etc?

Thank you! 

0 Likes