Edit in GitHubLog an issue

Tutorial Step 3 - Handling Specific Events

As seen in Step 1, webhooks can be registered for one or more events. Depending on the type of integration you are actually building with Cloud Manager, you will end up with a single webhook script which can handle multiple events in different ways. The event can be identified by using the combination of the @type and xdmEventEnvelope:objectType values. A full list can be found on the Receiving Events page. For this step in the tutorial, you're going to add a simple log statement when event being received is a Pipeline Execution Started event.

Updating the Webhook

Replace the app.post block with this code:

Copied to your clipboard
1app.post('/webhook', (req, res) => {
2 if (process.env.CLIENT_ID !== req.body.recipient_client_id) {
3 console.warn(`Unexpected client id. Was expecting ${process.env.CLIENT_ID} and received ${req.body.recipient_client_id}`)
4 res.status(400)
5 res.end()
6 return
7 }
8 res.set('Content-Type', 'text/plain')
9 res.send('pong')
10
11 const STARTED = 'https://ns.adobe.com/experience/cloudmanager/event/started'
12 const EXECUTION = 'https://ns.adobe.com/experience/cloudmanager/pipeline-execution'
13
14 const event = req.body.event
15
16 if (STARTED === event['@type'] &&
17 EXECUTION === event['xdmEventEnvelope:objectType']) {
18 console.log('received execution start event')
19 }
20})

Now when a Pipeline Execution Started event is received, the message received execution start event will be logged.

Running the Updated Webhook

If you are running the script locally, you'll need to stop and restart the node process. You don't need to restart ngrok. In fact, if you do restart ngrok, the URL will likely change and you'll need to go back into the Adobe Developer Console and update the Webhook URL.

If you are running the script through Glitch, Glitch will restart automatically. If you don't want to update your existing Glitch project (or lost it), you can click the button below to start over.

Remix in Glitch

Next Step

With all that done, you're ready to proceed to the next step. Continue to Step 4.

  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.