Catching json data from hubspot webhook

2019-07-30 09:42发布

问题:

For the life of me I can't figure out what I am missing. I am using HubSpot and have a workflow setup to use a web hook that posts to a script that I have. When I set the url to capture the webhook data onto requestb.in it passed the data and I can see the raw json data. But when I try to capture it with my own code and write it to a text file, I get absolutely nothing.

I have tried things like:

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $_POST);
fwrite($fh, $_GET);
fwrite($fh, $_REQUEST);
fwrite($fh, $_POST['message']);
fwrite($fh, $_GET['message']);

fclose($fh);

And no matter what I do - I can't capture the data being posted from the webhook.

So here's my question. In a normal procedure, when json data is posted from an api, am I correct in asking that the "variable" of the json data is usually "message" (For example: $_POST['message'])?

And I would kindly ask a pointer as to what I am missing or doing wrong that won't allow me to capture this data. I am really beginning to think it's HubSpot and not me, but I need to confirm that first.

Thanks

回答1:

I had luck with using this code at the top: $_POST = file_get_contents('php://input');



标签: php json hubspot