Hi,
I’m tearing my hair out here!
Authentication Request goes through fine, but the Access Token Request keeps returning “Invalid Grant”. Unfortunetly the API documentation is not the most helpful!
Can you see where I’m going wrong?
const tokenURL = 'https://api.freeagent.com/v2/token_endpoint'
const urlParams = new URLSearchParams(document.location.search)
const accessCode = urlParams.get('code')
const redirectURI = 'http%3A%2F%2F127.0.0.1%3A3000%2FBrowser%2Fapp.html'
const client_id = 'foo'
const client_secret = 'bar'
function returnToken() {
fetch (tokenURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
grant_type: 'authorization_code',
code: accessCode,
redirect_uri: redirectURI,
client_id: client_id,
client_secret: client_secret
})
})
.then(res => res.json())
.then(json => console.log('Success:', json))
.catch((error) => {
console.error('Error:', error);
});
}
Any help would be much appreciated!
Thank you