I am trying to send a POST request to the mailchimp api to add a new member to a list, but I keep getting an error saying that the api key is missing. When I send a get request I include the key in the URL and it works normal.
From the Mailchimp documentation it looks as though the api key should be part of the request and the parameters (email_address and status) part of the body, but I don't understand how to do that using requests. (I know there is a mailchimp module for Python, but I have some custom things to do and I want to get my head around this)
This is the POST I am trying to get going:
import requests
url="https://us15.api.mailchimp.com/3.0/lists/xxxxx/members/"
header ={"Authorization":"apikey xxxxx",
"email_address":"test@gmail.com",
"status":"subscribed"}
r=requests.post(url,header)
print r.text
The error I get reads: {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"API Key Missing","status":401,"detail":"Your request did not include an API key.","instance":""}
I also tried to put this request in Postman where you can easily separate the header and the body, but it gives the same response.
I also tried it using the Mailchimp3 package, but that gives me a bad request. The code I used is as follows:
from mailchimp3 import MailChimp
client = MailChimp('edgar@mymailserver.nl', '{}-{}'.format('xxxxxxxxxxxxxxxxxxxxxxx','us15'))
client.lists.members.create('2be23de2cc', {'email_address': 'john.doe@example.com','status': 'subscribed'})
However, I get the following error: requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://us15.api.mailchimp.com/3.0/lists/2be23de2cc/members