I have the following code to get access token from pinterest api as per Oauth when my callback handler is called in my express application, unfortunately the post method always throws 404 error. I can't find any error in my post payload as shown below
let url = 'https://api.pinterest.com/v5/oauth/token';
let accessTokenRequestBody = {
grant_type: "authorization_code",
code: code, //Received from pinterest at the top
redirect_uri: encodeURIComponent(redirectUrl) //declared at the top
}
const clientIdAndSecretBase64 = Buffer.from(`${clientId}:${clientSecret}`).toString('base64'); //clientId and clientSecret are both declared at the top
axios.default.post(url, accessTokenRequestBody, { //axios.post was not working so I switched to axios.default.post
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${clientIdAndSecretBase64}`
}
}).then((response) => {
let responseData = response.data;
console.log(`Pinterest ResponseData = ${JSON.stringify(responseData, null, 2)}`);
}).catch((e) => {
console.log(`Pinterest AccessToken Error=${e}`);
});
This is the error message I keep getting
Pinterest AccessToken Error=Error: Request failed with status code 400
What am I doing wrong here? Thanks for your input.