To make an API call to the portal, the following steps need to be followed.
1. Generate Access Token
function get_token(username,password){
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://your_institution_domain.com/oauth/token", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange=function(e)
{
if (xhr.readyState==4 && xhr.status==200)
{
console.log(e.target.responseText);
}
}
token=xhr.send("client_id=53a305cab608748as64eb6224831dab772105a989d8e454d4a8d8183afb560c414e2ef&client_secret=95318fad811212710db49aec17353c5983c10a1454cheadfthisis25sa25mp25le26a95e19c7c87dec332&grant_type=password&username="+username+"&password="+password+"&redirect_uri=http://localhost:3001/authorize");
return(token);
}
function callApi(token, path)
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(evt)
{
console.log("xhr.readyState :: "+httpRequest.readyState);
console.log("xhr.status :: "+httpRequest.status);
if (httpRequest.readyState==4 && httpRequest.status==200)
{
console.log(evt.target.responseText);
}
}
httpRequest.open('GET', 'http://your_portal_domain.com/api/'+path);
httpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
httpRequest.setRequestHeader('Authorization', 'Token token="'+token+'"');
httpRequest.send();
}