Webhook to PHP help

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:

// 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
} else {
        // The request is not authenticated
        header('HTTP/1.1 403 Forbidden');
        echo 'Invalid signature'; //so far I only get this  :(

Hi, I moved your post to a newer thread so you get more focused responses (hopefully).

Now, you are in total control of what you send. You can even just send the plain value to start with, no need to complicate with JSON.

When I get in trouble with webhooks, I use a webhook receiver or endpoint on https://pipedream.com/
From there, I can see EXACTLY what the webhook is sending, and develop the parsing I need on the receiving end.

Maybe you want to post more info about your integration so people can help you better?

Good luck!


@cuttingteeth there's also the Integrations -> logs section that can provide more info, perhaps you already been there, otherwise it's worth a shot:

Is pipedream better than postman (particle.io recommended)?

I updated my post with more details, including the test code for php. Thanks for making a new thread!

This post looks a lot different than what I am sending. What I have looks more like:

  "event": "{{{PARTICLE_EVENT_NAME}}}",
  "data": "{{{PARTICLE_EVENT_VALUE}}}",
  "coreid": "{{{PARTICLE_DEVICE_ID}}}",
  "published_at": "{{{PARTICLE_PUBLISHED_AT}}}"

...and my headers look like:

  "Content-Type": "application/json",
  "Accept": "application/json",
  "Authorization": "my secret"

I think they complement each other. Postman sends requests, while PipeDream receives requests.

sorry, no php here.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.