it:ad:mandrill:howto:develop_your_api_endpoints

IT:AD:Mandrill:HowTo:Develop your API endpoints

Summary

Your startup's service is on servers in the cloud, your SMTP service is sitting over on the Mandrill servers.

You send out emails, they bounce, people click things, they want to unsubscribe, etc. – they have to call back some API endpoints.

Unsubscribe

We've already covered what's need to process unsubscribe events:

You use webhooks:

The webhook request: * always uses the same data format, regardless of the event type. * is a standard POST request * with a single parameter - mandrill_events. * containing JSON.

Don't have a working example to show, but use the following snippets as starting points.

Get the Parameter

string mandrillEventsAsJson = System.Web.HttpContext.Current.Request.Params["mandrill_events"];

Whether you have to Decode it first is to be seen.

Parse the Json

Then process it:

void Main()
{
string jsonData = 
@"[
{""ts"":123,
 ""event"":""send"",
 ""url"":""http://foo.com"",
 ""user_agent"":""bar"",
 ""environment"":""bar"",
 ""location"":[
    {
     ""country_short"": ""en"",
     ""country_long"": ""en"",
     ""region"": ""en"",
     ""city"": ""en""
     }
   ],
 }
]
";


var r = JsonConvert.DeserializeObject<List<RootObject>>(jsonData);

r[0].url.Dump();

}

// Define other methods and classes here

public class Location
{
    public string country_short { get; set; }
    public string country_long { get; set; }
    public string region { get; set; }
    public string city { get; set; }
}

public class RootObject
{
    public int ts { get; set; }
    public string @event { get; set; }
    public string url { get; set; }
    public string user_agent { get; set; }
    public string environment { get; set; }
    public List<Location> location { get; set; }
}

Process, according to event type

Depending on the event value, update a database.

  • send
  • deferral
  • hard_bounce
  • soft_bounce
  • open
  • click
  • spam
  • unsub
  • reject

Customer.EmailAddressIsValid=false;
etc.

Make sure to respond with an OK.

See: https://github.com/martydill/mandrill-inbound-classes

  • /home/skysigal/public_html/data/pages/it/ad/mandrill/howto/develop_your_api_endpoints.txt
  • Last modified: 2023/11/04 01:48
  • by 127.0.0.1