curl 请求说地址需要是一个数组,而它已经是?

curl request says to address needs to be an array when it already is?

我正在尝试通过修改 https://mailchimp.com/developer/transactional/api/messages/send-new-message/ and using the API key from https://us1.admin.mailchimp.com/account/api/ 中的 curl 命令来使用 Mandrill 发送电子邮件,但我收到了一个对我来说意义不大的错误。这是我的命令 运行:

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"]}}'

这是回复:

{"status":"error","code":-2,"name":"ValidationError","message":"Validation error: {\"message\":{\"to\":[\"Please enter an array\"]}}"}

解码如下:

{
  "status": "error",
  "code": -2,
  "name": "ValidationError",
  "message": "Validation error: {\"message\":{\"to\":[\"Please enter an array\"]}}"
}

我不明白。 “to”是一个数组...

有什么想法吗?

谢谢!

我一开始也遇到了同样的错误,然后仔细检查 documentation,我注意到 message 中的 to 字段是 NOT 电子邮件地址列表。我知道这样很直观!!

这是一个包含 3 个字段的对象列表:电子邮件、姓名和类型。

一个理想的JSON身材应该是这样的:

{    
    "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>"
            }
        ]
    }
}