question

davidrichied avatar image
davidrichied asked davidrichied answered

How to Access Webhook Verification JSON data?

This is probably a simple question. I am trying to get the verification code ( https://docs.clover.com/build/webhooks/#verificati... from the Webhook Post request. Here is the code that I have in my PHP file.

$file = 'verification.txt';
$newdata = json_decode($_REQUEST);
$current = 'data: ' . json_encode($newdata);
file_put_contents($file, $current);

Typically, this would write the contents of a post, get, or request to a file in the same directory as the PHP file. I can confirm that the PHP file is being reached because the verification.txt file is created, but the $_REQUEST just appears as empty brackets ([ ]). I tried the same for $_POST, but that was empty as well. How can I easily retrieve the verification code? Is there a better way?

Thanks for the help!
API Token
10 |2000

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

Bryanne Vega avatar image
Bryanne Vega answered sam Deactivated edited
First send the SUCCESS message on header, Clover Webhook won't work without it. (It wont accept 200 OK) (Emailed dev@clover.com for a feature request for this already).

header(trim("HTTP/1.1 200 SUCCESS"));

Then get the input:
$content = json_decode(file_get_contents('php://input'),true);

Then save it to your file. Don't enable any modules yes so you don't get a big file P:

Hope it helped (It worked for me).
2 comments
10 |2000

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

davidrichied avatar image davidrichied commented ·

Yes! That worked! Thanks, Bryanne! I haven't been using PHP for too long (about 2 years), but I've never seen that method used before. I wonder if I would've been able to figure it out, eventually.

0 Likes 0 ·
davidrichied avatar image davidrichied commented ·
Hey @Bryanne Vega, another quick question. Do I have to do something with the X-Clover-Auth Code ? I ticked "Inventory - When inventory items are created, updated, or deleted." for the Webhook Subscriptions, but when I update the quantity of a product, I do not receive anything. Here is what I'm doing in my file. Thanks, again, for the help!

<?php
header(trim("HTTP/1.1 200 SUCCESS"));
$content = json_decode(file_get_contents('php://input'),true);
$file = 'clover-data.txt';
file_put_contents($file, $content);
0 Likes 0 ·
davidrichied avatar image
davidrichied answered
Hi @Sam Thanks for the suggestion to use requestb.in! I set up a request bin and got a verification, but if I update the quantity of an inventory item, nothing else happens. Here's the URL to the bin: https://requestb.in/rpf2v5rp?inspect I must be overlooking a something in Clover. Do you know if there are any other steps I should take besides subscribing to events? Do I have to set an application URL, application ID, or use the app secret somewhere? Does manually updating an inventory item via the web app ( https://www.clover.com/inventory) possibly not fire off a webhook request? Thanks, again for the help.
10 |2000

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

Welcome to the
Clover Developer Community