Home > Software design >  ServiceStack request object where a property contains a dash?
ServiceStack request object where a property contains a dash?

Time:07-01

I'm trying to consume the mailgun webhook data, but their eventdata is sent as "event-data"

https://documentation.mailgun.com/en/latest/user_manual.html#webhooks-1

So I see there's other posts where there's JsConfig stuff to globally change how SS behaves (Lenient property?) but I can't fundamentally DO that. If I was to use Lenient it would need to be just for this service and ideally this specific request POST eh. The system we're using implements ServiceStack on a core level so any JsConfig attempts we've tried seem to break things randomly in the CMS. But I do use and prefer SS for custom service routes.

How can I get SS to handle this EventData (event-data) locally?

    [Route("/mailgun/webhook")]
    public class MailgunWebhookListenerRequest : IReturn<string>
    {
        public MailgunWebhookSignature Signature { get; set; }
        public List<Dictionary<string, string>> EventData { get; set; } = new List<Dictionary<string, string>>();
    }
{
    "signature":
    {
        "timestamp": "1529006854",
        "token": "a8ce0edb2dd8301dee6c2405235584e45aa91d1e9f979f3de0",
        "signature": "d2271d12299f6592d9d44cd9d250f0704e4674c30d79d07c47a66f95ce71cf55"
    },
    "event-data":
    {
        "event": "opened",
        "timestamp": 1529006854.329574,
        "id": "DACSsAdVSeGpLid7TN03WA"
    }
}

CodePudding user response:

You can use .NET's DataContract attributes to customize serialization, e.g:

[DataContract]
public class MailgunWebhookListenerRequest : IReturn<string>
{
    [DataMember]
    public MailgunWebhookSignature Signature { get; set; }

    [DataMember(Name="event-data")]
    public List<Dictionary<string, string>> EventData { get; set; }
}
  • Related