Liu Chuyu Liu Chuyu - 1 month ago 4
PHP Question

how to write a php to get the json post from a webhook?

I add my url xxx/getjson.php to a webhook and once a person signup, it will post the json data to my url. I use to check the data and the result is like this:

payload{ "signup": { "address": { "address1": "XX",
"country": "United States"},

the php script i write is:

$obj=json_decode($_POST); //cannot get the json data


Also I don't know how to use the 'payload'

I find a similar sample code and I test it well using their web hooks.
However, they use 'data.json' rather than 'payload' as parameters.

$form_data = json_decode($unescaped_post_data['data_json']);
$userid= =$form_data->signup->id;

I used their stripslashes_deep function, and replaced the 'data_json' with 'payload' but still doesn't work.

I really appreciate your help.Thanks!


$_POST will be an array so you need to specify the key.

$obj=json_decode($_POST['payload']); // put the second parameter as true if you want it to be a associative array