V8-archive: Add web-hooks system

Created on 27 Mar 2018  Â·  6Comments  Â·  Source: directus/v8-archive

This feels like it's an easy one to add, but i might be wrong.

The API will call a provided url for any given hook.

The questions that remain are:

  • Where do we keep this mapping? (DB vs config.php)
  • Do we support multiple webhooks per event?
  • Do we even need to bother designing a specific way of handling this, seeing how easy it would be to throw in a http request using the normal events?
enhancement help wanted question

Most helpful comment

Key points missing in the discussion:

  • Do we retry failed webhooks?
  • Do we execute them from a queue or when it happens? (Thinking about cloud and saturating the service when in high load)
  • What are the policies to avoid saturating bandwidth? (For example avoid downloading 1 gb response from a webhook call)
  • How do we keep track of webhooks that failed?

    • Can admin manually retry them?

  • Can we fetch webhook status from api and retry them programatically?

All 6 comments

Webhooks can be implemented through event hooks

1. Database

  • We will create a new database table directus_webhooks with 4 column

    1. HTTP action (GET, POST)
    2. URL
    3. Directus action (item.create, item.update)
    4. Collection (Movie, Theatre, Files)
  • In web.php we will find and attach all the webhook to related hooks in the system, and then call the same callWebHook($action, $url, $data) as mention in Filesystem approach

  • We will have Webhook menu under Admin section where admin can manage webhook via App.
  • We will have a separate system entity Webhook just like Files and Users and Api endpoint.
  • We need to integrate this in GraphQL also as we have a separate API endpoint here.

2. Filesystem

  • Directus provide a function like callWebHook($action, $url, $data)
  • callWebHook() will do a CURL request to given $url
  • We will not send and relationship information in $data.
  • We will not send and files, the only id of files.

Question:🤔

How Directus Cloud support Filesystem based Webhook? Do cloud support execution of custom PHP code?

How Directus Cloud support Filesystem based Webhook? Do cloud support execution of custom PHP code?

It doesn't. There's no way for the end user to upload any custom extensions or code that's run.

The main use case for having web hooks (as of right now) is to ping an external service to either A: re-generate a static website, or B: process the saved data in another way (like send an email (SendGrid) or save it to a google doc or something.


It would be nice if there was a fifth column that allows for some additional options and settings. Being able to choose what format the payload has that goes to the external service would be extremely useful. You could for example use this setup to automatically create a release on GitHub that has the same information as the stuff you just entered in Directus, which makes Directus a control center for your app. Alternatively, being able to store credentials for these endpoints would be really useful too (so you can authenticate against SendGrid or whatever0

Just to connect the respective App ticket: https://github.com/directus/app/issues/1058#issuecomment-435046232

This mockup (pulled from GitHub's design) also has a content_type (as Rijk mentioned), a status column, and a secret column. Not sure if that helps! :)

Also, I guess the collection field would need to be conditional — and would we allow this to be a CSV, or would multiple collections require multiple hooks?

Key points missing in the discussion:

  • Do we retry failed webhooks?
  • Do we execute them from a queue or when it happens? (Thinking about cloud and saturating the service when in high load)
  • What are the policies to avoid saturating bandwidth? (For example avoid downloading 1 gb response from a webhook call)
  • How do we keep track of webhooks that failed?

    • Can admin manually retry them?

  • Can we fetch webhook status from api and retry them programatically?
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdwmhcc picture cdwmhcc  Â·  3Comments

benhaynes picture benhaynes  Â·  4Comments

metalmarco picture metalmarco  Â·  3Comments

binary-koan picture binary-koan  Â·  3Comments

cdwmhcc picture cdwmhcc  Â·  3Comments