I am having a devil of a time understanding how to attach to a webhook (POST
) to a php file with a generated particle.io API key. I have an index.php
at the webhook enpoint server-side, using file_get_contents()
. I do get a lot of "blue checkmark" circles in the particle console indicating that the webhook is operative. My issue is that I do not understand what sort of JSON
I need to be sending vs what I should be doing in my "receiver" code. The official documention differs in terms of what the UI looks like and also the nomenclature.
Does particle support this sort of usage of php in the browser? My goals are to send a value via Particle.publish(), generate some JSON in the webhook, and pick up on that somewhere else in a website. I just want to see a value change in an echo'd output to be honest. It's been mind bending trying to get this to work. I could email support I suppose.
Some details:
I think my first step is to print data to a webpage via an echo()
in php. That should be easy enough but I get an Invalid Certificate
error when I print. On the particle side it looks like everything is totally fine. Sound familiar? If so, what did you do to try to troubleshoot this?
I include my code below:
<?php
// Your secret key; generated token
$key = 'my secret'; //I assume that this is one of the keys I've generated myself via the particle CLI. I can print these and see that it is _not_ expired
// Get the actual signature
//$actualSignature = $_SERVER['HTTP_X_HUB_SIGNATURE'];
$actualSignature = $_SERVER['HTTP_AUTHORIZATION'];
// Get the raw POST data
$postData = file_get_contents('php://input');
// Calculate the expected signature
$expectedSignature = hash_hmac('sha256', $postData, $key);
// Check if the signature is valid
if($expectedSignature === $actualSignature) {
// The request is authenticated
// Process the webhook data
$data = json_decode($postData, true);
// Do something with $data
echo($data);
} else {
// The request is not authenticated
header('HTTP/1.1 403 Forbidden');
echo 'Invalid signature'; //so far I only get this :(
}