2
votes

I'm having trouble with Mailchimp token API. I've worked with OAuth a lot, but it seems something is not wokring with this API. Providing I've obtained authorization code from callback, the request to get token is like this:

URL: https://login.mailchimp.com/oauth2/token
Method: POST
Body
grant_type: "authorization_code"
client_id: client_id
client_secret: client_secret
redirect_uri: redirect_uri
code: code

client_id, client_secret and redirect_uri are exactly from Mailchimp Registered App configuration. I basically copy paste those 3 values to ensure valid information. And the response is

Bad request 400
{
  "error": "invalid_client"
}

I tried to send from server, from curl, from Postman. Still the same error. Can you guys help?

1
Did you get a response or solve this because I tried from curl and Postman and get the same error message that you did.user3757731
Having the same issue herevIceBerg
any success with this?DevLover

1 Answers

2
votes

I had the same issue with Python Requests. I was using urlencode on the dictionary data it was sent through the request:

Params = {
            'grant_type': 'authorization_code',
            'code': code,
            'redirect_uri': redirect_url,
        }
params = urllib.parse.urlencode(params)

tokenResponse = requests.post(access_token_url, data=params)

Once I removed the urlencode it worked:

Params = {
            'grant_type': 'authorization_code',
            'code': code,
            'redirect_uri': redirect_url,
        }
tokenResponse = requests.post(access_token_url, data=params)

I am by no means an expert in Oauth2 so I'm not sure why this worked. I thought when I read the documentation it stated that the POST was x-www-form-urlencoded, so I urlencoded the data. Make sure your body is in the correct format.