Get the data sent by MailChimp API V3 Webhook
<p>I'm trying to write a webhook for Mailchimp events using API version three and I'm struggling a bit due to their lack of a library, documentation, and basic examples, but also my lack of experience.</p>

<p>I know we should secure the webhook by putting a secret in the URL, that's fine. By the way, MailChimp doesn't allow configuration of basic access authentication in their portal.</p>

<p>They say "While we do send HTTP POST for actual data, our webhook validator will only send HTTP GET requests. You'll need to allow both in order for your webhook to function properly." Ok, I guess I can use Request.HttpMethod to return a success status code if it's a GET and process some data if it's a POST. </p>

<p>Not sure how to pick stuff out of the request though, and ideally don't want to write heaps of classes and properties to cover all the event types, C# being statically typed, although I guess the dynamic keyword is also an option.</p>

<p>Do I need to deserialise JSON? I've only written one webhook before for another API with the help of a library, you could construct an API event using either a string, stream, or textreader, which came from the request. The library made everything very simple.  </p>

<p>For reference, there's also this question which shows how to get some data using PHP: <a href="https://stackoverflow.com/questions/21028552/how-to-pass-email-address-to-webhook-from-mailchimp">How to pass email address to webhook from mailchimp</a></p>

<p>The data that gets posted looks like this (supposedly, there doesn't seem to be any documentation for V3):</p>

<pre><code>"type": "unsubscribe", 
"fired_at": "2009-03-26 21:40:57",  
"data[action]": "unsub",
"data[reason]": "manual", 
"data[id]": "8a25ff1d98", 
"data[list_id]": "a6b5da1054",
"data[email]": "api+unsub@mailchimp.com", 
"data[email_type]": "html", 
"data[merges][EMAIL]": "api+unsub@mailchimp.com", 
"data[merges][FNAME]": "MailChimp", 
"data[merges][LNAME]": "API", 
"data[merges][INTERESTS]": "Group1,Group2", 
"data[ip_opt]": "10.20.10.30",
"data[campaign_id]": "cb398d21d2",
"data[reason]": "hard"
</code></pre>

<p>I just basically need to get this data into variables so I can sync it with my database.</p>

<p>Here's my (skeleton) controller so far:</p>

<pre><code>[Route("mailchimp/newsletter-webhook/super-secret-key-goes-here")]
public HttpStatusCodeResult ChargeBeeWebhook()
{

    return new HttpStatusCodeResult(200);
}
</code></pre>