I have created a private app from my store and try to hit https://API_KEY:PASS@STORE_NAME/admin/orders.json URL using ajax and curl. It is working if I use curl but not with ajax. Can anyone explain here what is the issue?
I have created a private app from my store and try to hit https://API_KEY:PASS@STORE_NAME/admin/orders.json URL using ajax and curl. It is working if I use curl but not with ajax. Can anyone explain here what is the issue?
2
Answers
This might be a Cross origin problem. If you are using jQuery try to make an ajax call with
dataType
set tojsonp
as shown here:Like the other answer said, it’s a cross origin problem (See CORS)
Best way to deal with it normally is Shopify App Proxy, but this isn’t available to private apps, only custom apps. Best bet is to build a custom app and authenticate with OAuth2, assuming there’s no other reason you’ve chosen to build a private app instead.
If the nature of your app permits the change to a custom app, the App Proxy will give you a {store-name}.myshopify.com/{resource} end point that will bypass the cross-origin issue, but forward the request to your remote server.
Also, when you’re working with JS and something is not working, check the console, and share any errors. No one can really tell you why it’s not working without seeing either the code, the error, or both, but this is a common enough stumbling block with AJAX since all this cross-origin security stuff got put into place that I’m 90% sure it’s the answer.