【问题标题】:curl request says to address needs to be an array when it already is?curl 请求说地址需要是一个数组,而它已经是一个数组?
【发布时间】:2021-06-14 08:28:30
【问题描述】:

我正在尝试使用 Mandrill 通过调整来自 https://mailchimp.com/developer/transactional/api/messages/send-new-message/ 的 curl 命令并使用来自 https://us1.admin.mailchimp.com/account/api/ 的 API 密钥发送一封电子邮件,但我收到了一个对我来说没有多大意义的错误.这是我正在运行的命令:

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" 是一个数组...

有什么想法吗?

谢谢!

【问题讨论】:

    标签: mailchimp mandrill mailchimp-api-v3.0


    【解决方案1】:

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

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

    一个理想的 JSON Body 如下:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 2020-01-25
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 2022-08-10
      • 1970-01-01
      相关资源
      最近更新 更多