Path to my webhook listener on a plugin give a 404 error

Your software
My Mautic version is: v4.4.10
My PHP version is: 8
My Database type and version is: MySQL 8

Your problem
My problem is: Can’t correctly configure the URL for a webhook listener for a new plugin

These errors are showing in the log: No error log, just 404 on the URL

Steps I have tried to fix the problem: Read documentation.

The issue is as follows

Currently I have a fully functional plugin to send WhatsApp messages but now I need to get the messages back. I am using a platform called Zender as the bridge. So the plugin currently adapts the text message channel and modifies to send a specially constructed JSON to Zender thus Zender can resend that to WhatsApp.

Zender can also get the answers and resend them to outside services via a Hook. The structure of the Hook is this one: https://mauticinstallation.com/zender/receive/?phone={{phone}}&message={{message}}&time={{date.now}}&datetime={{date.time}}&key=WhateverSecurityKeyYouHaveConfiguredInThePlugin

So the "/zender/receive/ is supposedly already configured in the listener in the plugin but you can test it at.
You can see the plugin at GitHub - rcarabelli/Mautic-Zender-Plugin: Plugin to use Mautic with Zender to send WhatsApp messages but without this listening feature yet (currently working on it)

If you want to see the error online, try this link:

What I have added to the plugin is in


pathtomautic/plugins/MauticZenderBundle/Controller/WebhookController.php

< here begins php

namespace MauticPlugin\MauticZenderBundle\Controller;

use Mautic\CoreBundle\Controller\CommonController;
use Symfony\Component\HttpFoundation\Request;

class WebhookController extends CommonController
{
public function receiveAction(Request $request)
{
$key = $request->get(‘key’);

    if ($key !== 'WhateverSecurityKeyYouHaveConfiguredInThePlugin') {
        // Invalid key, reject the request
        return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED);
    }

    // Process the valid request...
}

}


This to process the payload

and at


pathtomautic/plugins/MauticZenderBundle/Config/config.php

– previous code –

],
'routes' => [
    'main' => [
        'mautic_zender_receive_webhook' => [
            'path'       => '/zender/receive',
            'controller' => 'MauticZenderBundle:Webhook:receive',
        ],
        // ... (other routes you may have)
    ],
],

– following code –


Supposedly doing that on “routes” it should work at /zender/receive but it seems I was wrong.
Read all this in the documentation at: Mautic Developer Documentation
Did a search for “listeners” in documentation and assummed that was the right way, but it seems I am wrong.

Any idea what I am doing wrong?

Already cleared cache and the plugin still works on the other functionalities, so that’s not the issue.

If someone can help me discovering how to activate that webhook listener will be very thankful.

Regards,

Renato

Hi,

if you want to add api route to the plugin you should put it under ‘api’ key in config.php.

Check these two files as an example:

Regards, M.

1 Like

Thanks Matic, you are a genius.
Finally got the listener working with this in the config file of the plugin:


‘api’ => [
‘mautic_zender_receive_webhook’ => [
‘path’ => ‘/api/zender/receive’,
‘controller’ => ‘MauticZenderBundle:Webhook:receive’,
‘method’ => ‘GET’
],
],


Now I can catch the webhook payload inside the plugin.
Was very important the use the /api/ in the URL. Why? No idea (yet) but works.

1 Like

You needed to add endpoint under ‘api’ key in config, because you are creating an api endpint. When you put it under ‘main’ or ‘admin’ key different middlewares are used.

And I do not think you need to add prefix to every endpoint in config with ‘/api’ since this is done for you by mautic core when you register endpoint under ‘api’ key.

1 Like

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.