Problems sending webhooks after page creation

Hey, I am working on a site where new pages published should send data to a webhook. I am currently stuck and don’t know why. I only want to send data from children pages of my “posters” page using the “posters-archive” template. This is what the hook in my config.php looks right now:

'page.create:after' => function (Kirby\Cms\Page $page) {
            $parent = $page->parent();

            // Only proceed if the parent uses the 'posters-archive' template and the page is listed (published)
            if ($parent->intendedTemplate()->name() === 'posters-archive' && $page->isPublished()) {
                $image = $page->images();
                $imageUrl = $image ? $image->url() : null;

                $payload = [
                'title'   => $page->title()->value(),
                'year' => $page-year()->toDate('Y'),
                'url'     => $page->url(),
                'image'   => $imageUrl,
                ];

                try {
                \Kirby\Http\Remote::post('https://hook.eu2.make.com/xxx', [
                    'data' => $payload
                ]);
                } catch (Exception $e) {
                // log the error for debugging
                }
            }
}

I use ngrok for localhost to send data to the webhook but I am getting no data on Make.com

Thank you in advance!

This code is wrong. $page->images() returns a collection of images (even if it has no elements), not a single image. And you cannot call the url() method on a collection.

It is now working for me! I have edited the code to use the page.changeStatus:after hook instead of page.create:after to trigger the webhook when I publish a page. This is the final code:

'page.changeStatus:after' => function (Kirby\Cms\Page $newPage, Kirby\Cms\Page $oldPage) {

    $parent = $newPage->parent();

    $isCorrectParent = $parent && $parent->intendedTemplate()->name() === 'posters-archive';
    $isNowPublished = $newPage->status() === 'listed';

    if ($isCorrectParent && $isNowPublished) {

        $image = $newPage->url() . '.jpg';

        $yearValue = null;
        if ($newPage->year()->isNotEmpty()) {
            $yearValue = $newPage->year()->toDate('Y');
        }
        
        $payload = [
            'title'   => $newPage->title()->value(),
            'year'    => $yearValue,
            'url'     => $newPage->url(),
            'image'   => $image,
            'tags'    => $newPage->socialtags()->value()
        ];

        $webhookUrl = 'https://hook.eu2.make.com/xxx';

        try {
            $response = \Kirby\Http\Remote::post($webhookUrl, [
                'data'    => json_encode($payload),
                'headers' => [
                    'Content-Type: application/json'
                ]
            ]);
            error_log('[Webhook DEBUG] Request sent. Response Code: ' . $response->code());
        } catch (Exception $e) {
            error_log('[Webhook CRITICAL ERROR] Exception caught: ' . $e->getMessage());
            error_log('[Webhook CRITICAL ERROR] Exception File: ' . $e->getFile() . ' on line ' . $e->getLine());
            error_log('[Webhook CRITICAL ERROR] Exception Trace: ' . $e->getTraceAsString());
        }
    } else {
        error_log('[Webhook DEBUG] Webhook not sent.');
    }
}