Home > OS >  MailChimp Net V3 - Merge Fields and Address object. C#
MailChimp Net V3 - Merge Fields and Address object. C#

Time:01-11

I'm using MailChimp.Net.V3 and I would like to know how to send an address to MailChimp API. I'm using C# and ASP.NET.

I've followed instructions from MailChimp.Net.V3 on adding a new contact with merge fields: https://github.com/brandonseydel/MailChimp.Net

See example code from MailChimp GitHub page. It doesn't show how to send the address via the merge fields.

var listId = "TestListId";

// Use the Status property if updating an existing member
var member = new Member { EmailAddress = $"[email protected]", StatusIfNew = Status.Subscribed };
member.MergeFields.Add("FNAME", "HOLY");
member.MergeFields.Add("LNAME", "COW");
await this.mailChimpManager.Members.AddOrUpdateAsync(listId, member);

I know from the MailChimp documentation that those Address fields exist. From the API documentation, the Address is an object type. https://mailchimp.com/developer/marketing/docs/merge-fields/

  • addr1
  • addr2
  • city
  • country
  • state
  • zip

I've tried plain text and JSON format. This is what I've tried.

member.MergeFields.Add("ADDRESS", "123 Freddie Ave");

member.MergeFields.Add("ADDRESS", "{ addr1: \"123 Freddie Ave\",city: \"Atlanta\",state: \"GA\",zip: \"12345\"}");

member.MergeFields.Add("ADDR1", "123 Freddie Ave");

member.MergeFields.Add("ADDRESS:ADDR1", "123 Freddie Ave");

member.MergeFields.Add("CITY", "Atlanta");

Every time I send a contact to the API via MailChimp.Net.V3, the Address field is blank.

Can you please help me to find the correct format for sending an address?

CodePudding user response:

Actually, the JSON string you tried was formatted incorrectly

According to this

this should work:

member.MergeFields.Add("ADDRESS","{\"addr1\":\"123 Freddie Ave\",\"addr2\":\"secondline\",\"city\":\"Atlanta\",\"state\":\"GA\",\"zip\":\"12345\",\"country\":\"USA\"}");
  •  Tags:  
  • Related