I’m struggling with capturing webhook data from HubSpot in my PHP script. When I test the webhook URL using external tools like requestbin, I can see the JSON payload arrives correctly. However, my PHP code isn’t capturing anything.
Nothing gets written to the file. I’m wondering if webhook JSON data typically comes through a specific POST parameter like ‘data’ or if I should be reading the raw input stream instead. Any ideas what I might be doing wrong here?
This is pretty common with webhooks. HubSpot sends data as JSON in the raw request body, not form parameters - that’s why $_POST is empty. You’re right to use file_get_contents(‘php://input’) for the raw payload. I hit the same issues when I integrated HubSpot webhooks last year. Usually it’s your PHP script failing silently because of file permissions or the script dying early. Try manually creating your log file first and setting write permissions. Also, switch to file_put_contents() instead of fopen/fwrite - it handles errors better. Check if your server’s even getting the requests. Look at your web server access logs to see if HubSpot is actually hitting your endpoint. Sometimes the webhook URL setup in HubSpot is the problem, especially with redirects or SSL cert issues.
Everyone’s right about the raw JSON input, but this is exactly why I ditched custom webhook handlers years ago.
Your code’s fine for basic logging, but webhook debugging sucks. Silent failures, file permissions, server configs - then you still gotta parse and validate JSON properly.
I used to waste hours on this until I realized automation platforms handle all the messy webhook stuff for you. Now I just point HubSpot webhooks straight to Latenode and let it handle parsing, logging, and errors automatically.
You get instant visibility into what’s coming through, proper error logs, and you can transform data however you want. Plus connecting to other services or databases is easy - no more PHP.
Way less headache than debugging file permissions and input streams. Takes 5 minutes to set up instead of hours troubleshooting.
Had this exact issue with HubSpot webhooks a few months back. Your PHP script’s probably erroring out before it writes to the log. HubSpot sends webhooks as raw JSON in the request body - not form data - so $_POST will always be empty. First, check if your script’s even running. Throw error_reporting(E_ALL) and ini_set(‘display_errors’, 1) at the top. Also wrap your file operations in try-catch blocks since file permissions fail silently all the time. Use file_get_contents(‘php://input’) but make sure the file path’s writable and your web server isn’t buffering requests. I had to use an absolute path for the log file and chmod 666 it to get mine working.