I'm using mailchimp api https://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/ to authorise my app using oAuth2. I can successfully retrieve access_code but when I make a request to https://login.mailchimp.com/oauth2/token to exchange it to access_token I get 400 error.
I'm using Request-Promise library https://github.com/request/request-promise
const data ="grant_type=authorization_code" +
"&client_id="+ constants.CLIENT_ID +
"&client_secret=" + constants.CLIENT_SECRET +
"&redirect_uri=" + encodeURIComponent(redirect_uri)+
"&code=" + 'access_code';
request({
method: 'POST',
uri: 'https://login.mailchimp.com/oauth2/token',
body: data
});
I have tried to send it as a JSON object but to no avail. I assume that body should contain a string. Sample Curl request example from the docs
curl --request POST \
--url 'https://login.mailchimp.com/oauth2/token' \
--data "grant_type=authorization_code&client_id= {client_id}&client_secret={client_secret}&redirect_uri={encoded_url}&code={code}" \
--include
Am I missing something?