How do I create a webhook?

So I figured it out, in a very simple way. Just point your webhook to a php with the following code:

<?php
// Original Answer
header('Content-Type: application/json');
$request = file_get_contents('php://input');
$req_dump = print_r( $request, true );
$fp = file_put_contents( 'request.log', $req_dump );

// Updated Answer
if($json = json_decode(file_get_contents("php://input"), true)){
   $data = $json;
}
print_r($data);
?>

And the information will be posted and then acessible through the 'request.log'

Hope it can help others in the future.


A webhook url is a place on your server where the above providers will send data from time to time when something happens and you need to know about, for example you might get a request each time a sms is sent, or each time a sms fails sending and based on that info you can take further actions, like marking the fact that user phone number isn't valid anymore.

Let's say your webhook url is something like https://www.yoursite.com/webhooks.php which means in your webhooks.php file you have to place some PHP code that will read the incoming request and will do something with the information that it contains.

Tags:

Php

Webhooks