I'm attempting to set up a quick POC of an Autodesk Viewing App but I'm running into issues with authentication. I've already checked the following questions for general help but they're either covering extremely specific issues like HashTableMapping or haven't even been answered:
According to Autodesk's documentation my request structure is totally fine but seems to be throwing a 415 error. Anyone have any ideas or see something I'm not seeing? Here's my code below:
var XmlHttpRequest = require("xmlhttprequest").XMLHttpRequest;
console.log("references loaded");
var xhr = new XmlHttpRequest();
xhr.open("POST", "https://developer.api.autodesk.com/authentication/v1/authenticate", false);
var headerRequest = "Content-Type: application/x-www-form-urlencoded";
var headerValue =
"client_id=_someSecretValue_" + "&" +
"client_secret=_someOtherSecretValue_" + "&" +
"grant_type=client_credentials" + "&" +
"scope=data:read";
xhr.setRequestHeader(headerRequest, headerValue);
xhr.send();
console.log(xhr.status); //getting a 415 here
console.log(xhr.statusText);
Got it - was my own faulty logic that screwed me up. The first request header wasn't formatted properly and I needed to send my information as a value:
var XmlHttpRequest = require("xmlhttprequest").XMLHttpRequest;
console.log("references loaded");
var xhr = new XmlHttpRequest();
xhr.open("POST", "https://developer.api.autodesk.com/authentication/v1/authenticate", false);
//var headerRequest = "Content-Type:application/x-www-form-urlencoded";
var headerValue =
"client_id=_someSecretValue_" + "&" +
"client_secret=_otherSecretValue_" + "&" +
"grant_type=client_credentials" + "&" +
"scope=data:read";
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(headerValue);
console.log(xhr.status);
console.log(xhr.statusText);