How to create an access token and make an API call to the institution portal

How to create an access token and make an API call to the institution portal

To make an API call to the portal, the following steps need to be followed. 


1. Generate Access Token


  • Register the Client App in the portal
    • Click on settings -> Manage Clients. 
    • Click on New to add a new client.
    • Enter name, redirect url and check on verified.
    • This will generate the Client Id & Client Secret which will be used to generate the access token
  • Generate the token
    • Pass the client id, secret, username and password to generate the access token. 
    • A sample code is given below:  

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);

}



    • Call the above function with the username and password as parameters.
    • Then call the API with the token and path (to get or post data) as parameters. A sample function is given below:

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();

  }



This will then give you the results. Here your_portal_domain.com is the url of your portal instance and localhost:3000/authorize is the redirect_url of your client app. The client id and secrets and uris given here are indicative only.

    • Related Articles

    • Successful implementation strategies of the portal in an institution

      Successful implementation of the portal or any other ERP solution in your institution requires 5% technical skills and 95% social skills.   Strategy 1 - A Team Make a team with maximum 5 employees of your institution and call this the A Team for ...
    • How to make teachers and employees of my institution to use your institution's portal efficiently?

      The portal is an enterprise solution which demands commitments from Teachers and non-teaching staffs of your organization to achieve its full potential and increase the efficiency of your organization. Successful implementation of the portal or any ...
    • What can I do with the portal API?

      The portal API allows you to tap into powerful features of the portal via various application outside of the institution portal. Using the API you can build custom applications that allow you to use data from the portal or enter data into the portal ...
    • What can I do with the portal API?

      The institution portal API allows you to tap into powerful features of the portal via various applications outside of said portal. Using the API you can build custom applications that allow you to use data from, or to enter data into the portal ...
    • How can I create polls in the portal?

      Only Admin or Privileged employee can create poll in the institution portal. At the top of your dashboard, click the module access icon > Collaboration> Poll> New Poll Provide the Title, Descriptions, update the Answers (option to poll) and select ...