Data api in javascript

(Improviz) #1

I would like to use the data api with javascript, but I am having a hard time figuring out how to build the request and send it to the proper api. Im sure I can figure out what to do with the response JSON that comes back. A simple example that comes to mind is how to get my collections.!/collections/get_v3_me_collections

Is there someone in the community that can provide an example of how to accomplish this?


(Shaderbytes) #2

like this :

function getCollections(){
if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();"GET", "" , false);
    xmlhttp.setRequestHeader( "Authorization", "Token yourtokenvalue")


You can get your token from your profile settings. Also this is a simple copy paste edit of some online code , the false value in the open method should be true instead (Synchronous call) and you should use an eventlistener on the XMLHttpRequest instance. You can see a sample of this listener on wikipedia or w3schools or all over the web :slight_smile:

(Improviz) #3

Thanks for the quick response @shaderbytes. I will give this a shot.


If you're using jQuery, it's even easier (although it's really just doing the same thing)