How to get around the CORS issue?

Schottky
Visitor
2 0 0

I am building a custom APP that needs to be able to create a product on the fly based on user creating a custom design via drag and drop.

 

I am able to get this to work with the XML API but found out today that this does not work on iphone... I also get error messages due to CORS issues and I was not able to figure out the proxy URL settings.

 

If there is anyone willing to help I would very much appreciate it.

 

APP is written in PHP and I use AJAX to create the product based on a custom page that enables user to create the design.

Replies 4 (4)

Alex
Shopify Staff
1561 81 341

Are you making Admin API requests from the front end? I definitely wouldn't recommend it if that's the case. Is there anything preventing you from delegating to a backend to more securely make authenticated requests? You shouldn't see CORS issues in that case.

 

Let me know if I'm misunderstanding anything though, more information would be appreciated in that case.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Schottky
Visitor
2 0 0
Hi Alex (great name!)
I was able to figure out much more and think I solved the CORS issue.

I added an app proxy to a public app and installed it in the store.
The custom product creation page creates the product by drag and drop and I'm making an AJAX call via jQuery to my app.
The app is written in PHP and is now making a CURL call to the Jason API
Is that common practice or should I do anything differently?
Alex
Shopify Staff
1561 81 341

To be clear, you're using the app proxy to make POST calls back to your app? While I don't think it's the intention of the app proxy, it's something I've seen done often. I'd consider it common practice.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Gregarican
Shopify Partner
1033 86 285

@Alex , I have be running this scenario for about a year now. But as of 18-Dec-2020 it has broken. Here's my post about the specifics --> https://community.shopify.com/c/Shopify-APIs-SDKs/Shopify-App-Proxy-new-CORS-error/m-p/996602#M60386. Any suggestions?

 

UPDATE: I figured it out. I'm defintely not Captain Obvious based on my initial troubleshooting. lol.