401 HTTP Basic: Access denied. when trying to request access token

Hi all,

I have a nodejs project I am working on for us to be able to integrate FreeAgent into various other systems we use. I am following the documentation and have got the Authorisation request working so I have the authorisation code.

Straight after getting the authorisation code I send a request from the client app to our internal api server with the auth code which then calls the token_endpoint but I am getting a 401 Access denied response and I can’t figure out why.

This is the code I am using to call the FreeAgent api:

try {

  let clientId = 'OAuth identifier from dashboard';
  let clientSecret = 'OAuth secret from dashboard';
  let base64 = btoa(`${clientId}:${clientSecret}`);
  let response = await axios.post(`https://api.freeagent.com/v2/token_endpoint`, {
    grant_type: 'authorization_code',
    code: authCode,
    redirect_uri: 'http%3A%2F%2Flocalhost%3A3001%2Ffreeagent%2Fconnected'
  }, {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Basic ${base64}`
    }
  });

  console.log(response);

} catch (error) {

  console.log(error);

}

Any help would be really appreciated! Thank you!

Hey there Will! :wave:

Thanks for sharing this info, it’s really helpful. I saw a more recent post where another dev is experiencing the same, so I’m going to have a look at this in more detail. I’m going to put everything in one place on this thread here, so if you have anything further to add we can carry on the conversation there. I’ll archive this thread so we have everything in the one place :smile: