paymoapp/api

Ability to track multiple events in a single webhook

urkle opened this issue · 1 comments

urkle commented

Currently the webhooks are limited to 1 event only.. This is problematic and limiting. It overly complicates consumers and the payload itself does not provide enough context as to what the event is.. (relying on more complicated means to determining that).. Also it does not match the behavior of other webhooks implementations for other task tools.

My proposal is this.
Adjust the payload to this

{
    "action": "model.insert.Task",
    "model": {
        "id":109403,
       "name":"New Task",
       "project_id":59032,
       "tasklist_id":250019,
       "user_id":1093,
       "other_fields": "etc..."
    }
}

And then allow multiple events to be subscribed to by allowing a "events" parameter instead of "event" when creating the webhook. e.g.

{
   "target_url": "https://myapp.com/paymo/notifications/hashyURL",
   "events": [
       "model.insert.Task",
       "model.update.Task",
       "model.delete.Task",
       "model.insert.Tasklist",
       "model.update.Tasklist",
       "model.delete.Tasklist"
    ],
    "secret": "Asecrethash"
}

Then if "events" is used to create the webhook, it can be marked as a "version 2" webhook internally so you can easily know what structure to send the payload in. This will allow backward compatibility with old code as they will still be using "event" and thus not accidentally opt-in to the new payload structure. You could even return a "version" field in the payload list response for easier identification of what type of webhook it is.