Skip to content

HowTo: Use a WebHook with WebAPI

Steve Tapley edited this page Aug 27, 2014 · 3 revisions

For an explanation of Mandrill WebHooks, see http://help.mandrill.com/entries/21738186-Introduction-to-Webhooks

The format of the WebHook is described http://help.mandrill.com/entries/24466132-Webhook-Format

To setup the binding model, create a class something like this:

public class MandrillWebHookBindingModel
{  
    public string mandrill_events { get; set; } 
}

Then in your controller, set up the method to receive the WebHook like so:

using Mandrill;
using Newtonsoft.Json;

public class Controller : ApiController
{
    [HttpPost]
    public IHttpActionResult MailProviderWebHook(MandrillWebHookBindingModel model)
    {          
        var events = JsonConvert.DeserializeObject<IEnumerable<WebHookEvent>>(model.mandrill_events);
        foreach (var mailEvent in events)
        {
            // do your processing here
        }

        return Ok();
    }
}
Clone this wiki locally