Pass a variable from pageFunction() via Webhooks JSON

Im trying to pass a returned variable from pageFunctions via webhooks, but I cannot get the value. My code: async function pageFunction(context) { await context.skipLinks(); const $ = context.jQuery; const pageTitle = $('title').first().text(); const matches = pageTitle.match(/((\d+))/); const numberOfTests = 0;
if (matches !== null) { numberOfTests = parseInt(matches[1]); } context.log.info(${numberOfTests}) return { numberOfTests } } Webhooks integration JSON: { "tests": {{resource.numberOfTests}} } What am I doing wrong? I tried also: { "tests": {{numberOfTests}} } but this returns a validation error.
3 Replies
rival-black
rival-black2y ago
The webhooks don't have access to the data, only to resource.defaultDatasetId. You have to load the data in the code called by the webhook
vicious-gold
vicious-goldOP2y ago
Thank you @Lukas Krivka Could you please point me to some basic examples on how to do this? Im just trying to scrape a website behind a login (that I've managed to acheive) to see if there is something available, and pass this boolean variable via a webhook to my Home Assistant
rival-black
rival-black2y ago
You have 2 options: 1. create a new webhook in the interface, then the webhook sends you info about the run and you have to pull the results with another API call 2. if you have your own actor, you can attach dynamic webhook at the end of the run and add the results thre directly

Did you find this page helpful?