0

Here's an (php) example of creating an Event and pushing it to MailChimp. Anybody knows how this can be accomplished using C# and MailChimp Net V3?

PHP-example: https://mailchimp.com/developer/marketing/guides/track-outside-activity-events/#create-an-event

Nicke
  • 365
  • 4
  • 8
  • 25

1 Answers1

0

I've found a way, though you'll need to create a new Logic class.

public class MemberEventResponse
{
}

public class MailChimpMemberEventLogic : BaseLogic
{
    public MailChimpMemberEventLogic( MailChimpOptions options )
        : base( options )
    {
    }

    public async Task<MemberEventResponse> CreateMemberEventAsync( string listId, string email, string eventName )
    {
        var baseUrl = $"/lists/{listId}/members/{Hash(email)}/events";
        using ( var client = CreateMailClient( baseUrl ) )
        {
            var response = await client.PostAsJsonAsync( "", new { name = eventName } ).ConfigureAwait( false );
            await response.EnsureSuccessMailChimpAsync().ConfigureAwait( false );

            var listActivityResponse = await response.Content.ReadAsAsync<MemberEventResponse>().ConfigureAwait( false );
            return listActivityResponse;
        }
    }
}

Then you just need to instantiate it, and create the event.

var logic = new MailChimpMemberEventLogic( _mailChimpOptions );
await logic.CreateMemberEventAsync( _mailChimpListId, email, eventName );

NB, I haven't looked into the response contents...

AnteSim
  • 1,265
  • 1
  • 12
  • 11