Netlify-cms: Add support for Custom Webhook Triggers

Created on 29 Feb 2020  路  6Comments  路  Source: netlify/netlify-cms

Feature Request

Add general support to trigger custom Webhooks defined per Collection (and per action type if possible).

This should unlock many possibilities when connected with services like Zapier.

All 6 comments

There鈥檚 this, but it鈥檚 not per collection: https://www.netlifycms.org/docs/beta-features/#registering-to-cms-events

Can you share your use case? That would help us prioritize the request.

Sent with GitHawk

Let's say I have two collections, one named Articles, and the other Products.

When an Article is created (not deleted or edited), I want to be able to trigger a webhook that automatically tweets the title and link of the article page.
I only want that for Articles, not Products.

I believe there are many such possibilities that can be unlocked by allowing webhooks at the per collection per action type level.

(Also, thanks for letting me know about the "registering to cms events" beta feature. I didn't know that existed)

If there's any way I can use CMS.registerEventListener for my use case described earlier, please let me know.

registerEventListener is close to what you need. I believe you can get the collection from the entry, so the only other thing you would need to know is whether the entry being published is new.

Sent with GitHawk

Thanks for your support.

I'm able to use registerEventListener for my use-case like:

import CMS from 'netlify-cms-app'

CMS.registerEventListener({
  name: 'postPublish',
  handler: ({ entry }) => {
    console.log(`entry.newRecord:`, entry.newRecord) // true
    console.log(`entry.collection:`, entry.collection) // 'articles'
    console.log(`entry.data:`, entry.data) // { ... }

    if (entry.newRecord && entry.collection === 'articles') {
      // trigger webhook here
    }
  }
})

Ah, newRecord is included, nice!

Sent with GitHawk

Was this page helpful?
0 / 5 - 0 ratings