How to create an access token and make an API call to Fedena

Modified on Mon, 5 Oct, 2015 at 11:08 AM

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


1. Generate Access Token

  • Register the Client App in Fedena
    • Click on settings -> Manage Clients. 
    • Click on New to add a new client.
    • Enter name, redirect uri 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.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_fedena_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_fedena_domain.com is the url of your fedena instance and localhost:3000/authorize is the redirect_uri of your client app. The client id and secrets and uris given here are indicative only.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article