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 BlogPost
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:
- give it a name (e.g. Edit counter)
- set the type to
Synchronous (block and wait for response)
- provide the URL where your processing app is available
- check the
Enabled
field - select the
Update
action to trigger the webhook - pick the
BlogPost
Content Type Definition as a source for thie webhook.
- Once the webhook is added - each update on a
BlogPost
object will call the service above and theedit_counter
field will be incremented!