如何使用Mailchimp API v3创建具有ADDRESS的列表成员

时间:2016-07-15 16:30:01

标签: mailchimp mailchimp-api-v3.0

ADDRESS是一个合并字段,但文档(http://server/myservice)并不清楚如何将其传递给API,因为它有街道,邮编,城市等的子字段。有没有人有一个例子如何这样做?

6 个答案:

答案 0 :(得分:8)

这个JSON有效:

{
  "addr1" : "first line",
  "addr2" : "second line",
  "city" : "city",
  "state": "state",
  "zip": "zip code",
  "country": "country"
}

这里的架构记录了: https://us1.api.mailchimp.com/schema/3.0/Lists/Members/MergeField.json

答案 1 :(得分:1)

它对我有用(php)

GridBagLayout

答案 2 :(得分:0)

合并字段可以这样传递:

'FNAME' => $contact->first_name,
'LNAME' => $contact->last_name,
'ADDRESS' => (Object)[
        'addr1' => $contact->fulladdress,
        //'addr2' => $contact->address2,
        'city' => $contact->city,
        'state' => $contact->state_region,
        'zip' => $contact->zip_postal_code,
        'country' => $contact->country->shortcode,
        'language' => $contact->language->code,
 ],

答案 3 :(得分:0)

以防万一有人遇到相同的问题。

我创建了自己的地址类,并尝试将ADDRESS-MergeField设置为JSON字符串,如下所示:

member.MergeFields["ADDRESS"] = Newtonsoft.Json.JsonConvert.SerializeObject(MyAddressObject);

这不会设置地址,但也不会返回错误。


相反,需要设置Dictionary<string, object>

var adr = new Dictionary<string, object>
{
    { "addr1", "123 Whatever" },
    { "addr2", "" },
    { "city", "New York" },
    { "state", "NY" },
    { "zip", "12345" },
    { "country", "US" }
};

member.MergeFields["ADDRESS"] = adr;

答案 4 :(得分:0)

Python答案

我遇到错误,因为地址行1为空。这是一个有效的复制和粘贴代码:

gawk

答案 5 :(得分:0)

您可以创建自己的地址类并按如下方式分配

  public class Address
    {
        [JsonProperty("addr1")]
        public string Address1 { get; set; }

        [JsonProperty("addr2")]
        public string Address2 { get; set; }

        [JsonProperty("city")]
        public string City { get; set; }

        [JsonProperty("state")]
        public string State { get; set; }

        [JsonProperty("zip")]
        public string Zip { get; set; }

        [JsonProperty("country")]
        public string Country { get; set; }

    }

     var address = new Address()
                                {
                                    Address1 = "1 Main Street,
                                    Address2 = "",
                                    City = "Brooklyn",
                                    State = "NY",
                                    Zip = "11299",
                                    Country = "US"
                                };

member.MergeFields["ADDRESS"] = address;