Sync Webhook examples¶
Example with payload modification¶
In this example we will see how to modify one of the fields of a content object in an external system.
On each update of a Blog Post
object we will increment the field edit_counter
.
-
Add the
edit_counter
field toBlogPost
CTD, set the field type tonumber
and default value to 0. -
Let's take the following simple app as an example of an external system:
const express = require('express') const app = express(); app.use(express.json()); const port = 8000; app.post('/increment-edit-counter', (req, res) => { const payload = req.body.payload; payload.edit_counter + 1; const response = { type: "response", subject: "content-object", event: "pre-create", response: {}, payload: {payload} }; res.send(response); })
-
Add a webhook:
- Once the webhook is added - each update on a
Blog Post
object will call the service above and theedit_counter
field will be incremented!