Apify and Crawlee Official Forum

Updated 5 months ago

Pass a variable from pageFunction() via Webhooks JSON

At a glance
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.
L
M
4 comments
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
Thank you 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
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
Add a reply
Sign up and join the conversation on Discord