Trigger CC via a Webhook
Webhooks can be configured to trigger a CloudCode task automatically. When the webhook fires, the task is automatically enqueued and executed.
To trigger a task called my_job_card_ready whenever a job_card is created on the backend, add the following webhook definition in the data model:
<model name="job_card" label="Job Card">
<!-- ... -->
<webhook type="ready" receiver="cloudcode" action="my_job_card_ready" />
</model>In the CloudCode Task:
export async function run(event) {
let object;
if(this.source == CloudCode.WEBHOOK) {
// Webhook
object = event.object;
// The object has the state of when the webhook was
// triggered, which may be out of date. To work with the
// current version, add:
// await object.reload();
} else if(this.source == CloudCode.EDITOR_TEST && this.env == 'testing') {
// Test - Create mock object
object = DB.job_card.create();
} else {
throw new Error('Task must be run as a webhook');
}
// Do something with the object here.
}Here's an example of a task that sends an email to a specified email address on a webhook:
You can learn more about JourneyApps Webhooks in the documentation below:
Webhooks (External)Last updated