I am trying to pull customers info from webhook but I am receiving empty string when I try to print it. Here is my endpoint URL:
Here is my PHP code:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$data = file_get_contents('php://input');
$acion=json_decode($data,true);
var_dump($acion);
exit();
?>
I am getting NULL printed on my webpage. Any help is greatly appreciated.
CodePudding user response:
Your script is expecting a valid JSON-encoded request body, so you should test it accordingly. You cannot simply access the URL in your web browser, because there is no request body sent that way. Instead you need to use some tool which is capable sending such requests, e.g. Postman:
As you can see in the above screenshot, given the correct input, the output is also correct.
CodePudding user response:
There is no error in your code.
The reason you getting NULL may be the data you are receiving is not in JSON format.
You can check that by printing $data variable without decoding it with json_decode()
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$data = file_get_contents('php://input');
echo $data;
exit();
?>
And the second reason could be you are receiving data with a GET request. Then you can access data with $_GET[]
.