I set up a webhook in Discourse today for the first time. I’ve got a great use case for it and can’t wait to finish the code.
But the post and topic event JSON sent by Discourse is not playing well with my receiving PHP script. PHP fails to parse it. Through json_last_error_msg
, I saw that there is a syntax error somewhere in the payload, which is why json_decode
is failing.
From the webhook’s log panel in Discourse, the request JSON validated when I tested it, so I set up a simple script to verify that PHP is receiving the same data that Discourse is reporting, but that doesn’t seem to be the case.
<?php
$data = file_get_contents('php://input');
print_r($data);
?>
Discourse receives a response that seems to show that a closing brace is omitted in the payload being received by PHP.
Here’s the well-formed JSON payload reported by Discourse:
…and here’s what print_r
returns to Discourse: