I'm trying to send an email out using Mandrill by adapting the curl command from https://mailchimp.com/developer/transactional/api/messages/send-new-message/ and using the API key from https://us1.admin.mailchimp.com/account/api/ and I'm getting an error that doesn't make a lot of sense to me. Here's the command I'm running:
curl -X POST \
https://mandrillapp.com/api/1.0/messages/send \
-d '{"key":"...","message":{"html":"hello, world!","subject":"hello, world!","from_email":"neubert@neubert.com","to":["neubert@neubert.com"]}}'
Here's the response:
{"status":"error","code":-2,"name":"ValidationError","message":"Validation error: {\"message\":{\"to\":[\"Please enter an array\"]}}"}
Here it is decoded:
{
"status": "error",
"code": -2,
"name": "ValidationError",
"message": "Validation error: {\"message\":{\"to\":[\"Please enter an array\"]}}"
}
I don't understand. "to" is an array...
Any ideas?
Thanks!
I also got the same error at first then going through the documentation keenly, I noticed that the to
field in message
is NOT a list of email addresses. I know it's intuitive that way!!
It's a list of object's with 3 fields: email, name and type.
An ideal JSON Body will be as follows:
{
"key": "<YOUR_MANDRILL_API_KEY>", # Caution! It is not a mailchimp API key
"message": {
"html": "testing html part",
"text": "testing text part",
"subject": "testing subject",
"from_email": "<FROM_EMAIL_ADDRESS>",
"from_name": "<FROM_NAME>",
"to": [
# Recipient 1
{
"email": "<Recipient1_EMAIL_ADDRESS>",
"name": "<Recipient1_NAME>"
},
# Recipient 2
{
"email": "<Recipient2_EMAIL_ADDRESS>",
"name": "<Recipient2_NAME>"
}
]
}
}