MailChimp API - oauth2 access_token request error

时间:2018-09-19 08:18:12

标签: node.js oauth-2.0 httprequest mailchimp-api-v3.0 request-promise

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?

0 个答案:

没有答案