How to use Webhooks?


#1

Hello. I’m playing around with a development version of Ushahidi to figure our if it’s the right platform for me. I followed the instructions to spin up the platform via vagrant and the client via gulp. I’m having a little trouble with using Webhooks, I’m hoping someone can help me out.

I set up a Webhook to send to a local address when a post is created, created a post, but nothing came through. Tried again with a VPS address, same thing. I confirmed the connection was working by doing a HTTP GET on the same address from my development machine

I couldn’t find any documentation on it except about setting up a cronjob to run ./bin/ushahidi webhook send, so I ran that in the vagrant instance and got:

"errors": [
        {
            "status": "Deprecated",
            "title": "The each() function is deprecated. This message will be suppressed on further calls",
            "message": "The each() function is deprecated. This message will be suppressed on further calls",
            "class": "ErrorException",
            "file": "/home/vagrant/Code/platform-api/vendor/aura/di/src/Factory.php",
            "line": 622,
            "trace": [
                {
                    "function": "error_handler",
                    "class": "Kohana_Core",
                    "type": "::",
                    "args": [
                        8192,
                        "The each() function is deprecated. This message will be suppressed on further calls",
                        "/home/vagrant/Code/platform-api/vendor/aura/di/src/Factory.php",
                        622,
                        {
                            "entity": false,
                            "traits": {
                                "Ushahidi\\Core\\Traits\\Event": "Ushahidi\\Core\\Traits\\Event"
                            }
                        }
                    ]
                },
...

Any ideas? Am I misunderstanding/misconfiguring the Webhooks?

The functionality I’m hoping to use Webhooks for is to build a service to notify users about posts in a particular region. I don’t suppose something like that already exists in the platform?

Cheers,
Xiao


#2

Hi Xiao,

what PHP version are you running this with? We are using PHP 5.6.x


#3

Good question. I didn’t change any of the default configs for the vagrant image.

The platform version of php in the vagrant instance is 7.2.3. Is that the version that ushahidi-platform is using for it’s execution? Or does it bundle it’s own in?


#4

Ah yes, you were bang on about the php version. I changed the command to

php7.1 bin/ushahidi webhook send

and got

+-------------------------+
| Message                 |
+-------------------------+
| 2 webhook requests sent |
+-------------------------+

Still not seeing anything come through in netcat. Are there logs I can check? application/logs only has those wrong php version errors


#5

Ahh okay turns out any webhooks that don’t specify a specific source and destination field of a survey don’t get processed.

Changing this line:

if ($post->form_id == $webhook['form_id']) {

in Console/Webhook.php to

if (!$webhook['form_id'] || $post->form_id == $webhook['form_id']) {

fixes it by only checking the form id if the webhook specifies one.