Skip to content
Advertisement

Issues creating a PHP webhook for Twilio

So I have the following CURL command in PHP, if I send it https://webhook.site I can extract all the required data in JSON format.

Instead of using webhook.site, I would like to create my own PHP webhook client.

The code below is the CURL command that works 100% when using webhook.site:

JavaScript

I then tried to use PHP to create a basic webhook just to pull the data:

JavaScript

But I keep coming with a blank request.log file – what am I doing wrong??? Thanks in advance

Advertisement

Answer

Twilio developer evangelist here.

By default, curl will make a POST request with the Content-Type header application/x-www-form-urlencoded. This is actually the same content type that Twilio uses when it sends a webhook request.

Your PHP to receive the request is trying to json_decode the data, which won’t work with form encoded data. Instead, you can access $_POST to get an associative array of the parameters sent to your script. You can then write them to a log file however you like.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement