Encountered a 400 Bad Request error while trying to exchange the code for an access token at .
I am unsure of the cause and would appreciate any assistance. Below is the code:
const GetAsanaAccessToken = async (req, res) => {
const body = {
grant_type: 'authorization_code',
client_id: process.env.NEXT_PUBLIC_ASANA_CLIENT_ID,
client_secret: process.env.ASANA_CLIENT_SECRET,
redirect_uri: process.env.NEXT_PUBLIC_ASANA_REDIRECT_URI,
code: req.body.code // The code obtained in the previous flow goes here.
};
console.log({ body });
const url = 'https://app.asana.com/-/oauth_token';
const response = await fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify(body)
})
.then((res) => {
console.log({ res });
return res.json();
})
.catch((err) => {
console.log({ err });
return err;
});
res.status(200).json(response);
};
export default GetAsanaAccessToken; Then { res } will be like this
{
res: Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null },
[Symbol(Response internals)]: {
url: 'https://app.asana.com/-/oauth_token',
status: 400,
statusText: 'Bad Request',
headers: [Headers],
counter: 0
}
}
}
I have also posted this question in the Asana forum without resolution.