Attempting To Access Shopify Api From Localhost With A GET Request

- 1 answer

Currently I'm trying to access data from my shopify store through local host and I'm getting the CORS error. I realize this question has been asked but I couldn't find an answer. Also I realize that this is a bad practice since credentials are exposed. I have a local computer that for a reason (with out taking the time to explain it) needs to be able to GET data from my shopify store. This HAS to be done in javascript so I am using XMLHttpRequest like so:

var url = "https://apikey:[email protected]/admin/orders.json?limit=25&page=2"; 

this is based on this answer on SO: shopify how to get product data using php in my localhost

In the above I'm passing my apikey and secret key from an app I've setup and approved on my account. One thing I didn't do is whitelist my ip which I'm not sure if that's what would allow me to get the data. This returns a CORS error.

I've also tried this:

var url = "https://username:[email protected]/admin/orders.json?limit=25&page=2";

Here I pass my username and password and I get the CORS error also.

What is a challenge is that if I'm logged into the account or not logged in when I go to my browser window I can go to this url: "https://username:[email protected]/admin/orders.json?limit=25&page=2"; and the json data appears in my browser window.

Again this has to be done in javascript and it has to be done from a local computer.



The way I went about this is forget the XMLHttpRequest. To access the shopify api via my local host I used the node library provided here:

I'm marking this as the answer just in case someone in the future is attempting to do this.