使用Mailchimp API批量订阅用户

时间:2019-05-22 21:47:15

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

根据此处https://developer.mailchimp.com/documentation/mailchimp/reference/lists/#create-post_lists_list_id的API文档,API可以通过发送包含成员字段的JSON对象来批量订阅多个用户。该成员字段是状态,电子邮件地址和merge_fields的数组。

在发送以下cURL查询时,我收到一条响应,指出找不到email_address字段。

curl -X POST \
  https://us15.api.mailchimp.com/3.0/lists/123456789/members \
  -H 'Authorization: Basic SSSSHWONTTELL=' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{"members": [{"email_address": "myuser@yahoo.fr", "status": "subscribed", "merge_fields": {"LNAME": "ANQUE", "FNAME": "PATRICIA"}}]}'

响应:

{
    "type": "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
    "title": "Invalid Resource",
    "status": 400,
    "detail": "The resource submitted could not be validated. For field-specific details, see the 'errors' array.",
    "instance": "xxxx-xxxx-xxxx-xxxx-xxxxxxxx",
    "errors": [
        {
            "field": "email_address",
            "message": "This value should not be blank."
        }
    ]
}

就API文档而言,该查询对我来说看起来不错。我可能错过了一些东西。有什么想法吗?

请注意,该查询对于以{email_address:XXX,status:XXX,merge_fields:XXX}发送的单个成员均适用,但是我希望我可以发送这些数组。

1 个答案:

答案 0 :(得分:0)

@Jalasem建议,删除/ members可以解决此问题。