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. https://docs.sketchfab.com/data-api/v3/index.html#!/collections/get_v3_me_collections
Is there someone in the community that can provide an example of how to accomplish this?
function getCollections(){
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "https://api.sketchfab.com/v3/me/collections" , false);
xmlhttp.setRequestHeader( "Authorization", "Token yourtokenvalue")
xmlhttp.send(null);
console.log(xmlhttp.responseText);
}
}
getCollections();
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