question

hampusbankler avatar image
hampusbankler asked

How to handle the POST from a webhook?

[Managed to solve this on my own. Solution posted below.]

I have a custom event. I have setup a webhook in PlayStream that points at a php page that is supposed to take whatever is included in the call and put it in a DB.

I have verified that the webhook successfully calls the right url, but I don't know how to get the json data from the POST variable on the php side. Can't find anywhere how to do that. My web programming skills are very low, so this might be a stupid question?

$eventData = $_POST["pleaseTellMeWhatWeShouldWriteHere"];

I expect $eventData to become the full event json string, but I may have misunderstood things?

Thank you!

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

hampusbankler avatar image hampusbankler commented ·

In fact, if I instead write:

$eventData = count($_POST); 

or

$eventData = count($_REQUEST);

$eventData becomes '0'. Which to me looks like there is nothing at all provided in the call?

0 Likes 0 ·
hampusbankler avatar image hampusbankler commented ·

*removed this post and posted answer. missed the "convert to answer button"*

0 Likes 0 ·

1 Answer

·
hampusbankler avatar image
hampusbankler answered

Managed to solve it now. If any other web newbie (like me) struggles with this... Apparently, sending something with POST doesn't imply that the $_POST variable is populated. To get the json data, this is what I had to do:

$json = file_get_contents('php://input'); //This extracts the POST data.
postEventToDatabase($json); //This is my own function that handles the string.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.