gpt4 book ai didi

java - Mailchimp API 帖子成员(member)批量操作

转载 作者:行者123 更新时间:2023-12-01 16:20:26 24 4
gpt4 key购买 nike

我发现,当我向 Mailchimp API 提交批量操作以将成员添加到 Mailchimp 受众时,操作失败并出现此错误...

[{\"field\":\"email_address\",\"message\":\"This value should not be blank.\"}]

这很奇怪,因为我的批处理操作指定了 email_addresses。

        ArrayList<MailchimpOperation> operations = new ArrayList<MailchimpOperation>();
for (Contact contact : contacts) {
MailchimpOperation operation = new MailchimpOperation();
operation.method = "POST";
operation.path = "lists/" + audienceid + "/members";
NewMember newMember = new NewMember();
newMember.email_address = contact.email;
MergeFields mf = new MergeFields();
mf.FNAME = contact.firstname;
mf.LNAME = contact.lastname;
newMember.merge_fields = mf;
newMember.status = "subscribed";
operation.body = newMember.toString();
operation.operation_id = "add_batch_" + batchNumber + "_to_mailchimp_audience_" + audienceid;
operations.add(operation);
}

我在一些堆栈溢出帖子中看到,operation.body 应该是一个 JSON 对象。我也试过这个...

ArrayList<MailchimpOperation> operations = new ArrayList<MailchimpOperation>();
for (Contact contact : contacts) {
MailchimpOperation operation = new MailchimpOperation();
operation.method = "POST";
operation.path = "lists/" + audienceid + "/members";
NewMember newMember = new NewMember();
newMember.email_address = contact.email;
MergeFields mf = new MergeFields();
mf.FNAME = contact.firstname;
mf.LNAME = contact.lastname;
newMember.merge_fields = mf;
newMember.status = "subscribed";
operation.body = newMember;
operation.operation_id = "add_batch_" + batchNumber + "_to_mailchimp_audience_" + audienceid;
operations.add(operation);
}

这会产生错误...

Mailchimp error: The resource submitted could not be validated. For field-specific details, see the 'errors' array.,mailchimp error 1 Schema describes string, object found instead,mailchimp error 2 Schema describes string, object found instead

如果我像这样显式设置操作.body,操作就会成功......

operation.body = "{\"merge_fields\":{\"FNAME\":\"" + contact.firstname + "\",\"LNAME\":\""
+ contact.lastname + "\"}, \"email_address\":\"" + contact.email + "\", \"status\":\"subscribed\"}";

那么为什么我设置 operation.body = newMember.toString() 的第一种方法会失败?

最佳答案

解决方案是不使用 .toString(),而是使用这个...

    operation.body = new ObjectMapper().writeValueAsString(newMember);

关于java - Mailchimp API 帖子成员(member)批量操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62299432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com