My events are still Unverified - not getting verified using autoverify

I ran this script : https://github.com/infusionsoft/infusionsoft-php/blob/master/samples/verifyRestHook.php
but the events are still unverified.

I cross-checked with a list-hook-subscriptions.php script.

php list-hook-subscriptions.php
[{“key”:“7”,“eventKey”:“invoice.payment.add”,“hookUrl”:“https://www.mydomain.com/is-hook.php",“status”:“Unverified”},{“key”:“3”,“eventKey”:“invoice.payment.add”,“hookUrl”:“https://www.mydomain.com/is-hook.php”,“status”:“Unverified”},{“key”:“1”,“eventKey”:“invoice.payment.add”,“hookUrl”:“http://infusionsoft.app/verifyRestHook.php”,“status”:“Unverified”},{“key”:“5”,“eventKey”:“invoice.payment.add”,“hookUrl”:“https://www.mydomain.com/is-hook.php”,“status”:"Unverified”}]

What am I doing wrong here ?

Place this code at the very top of your script and re-run the verification:

/**
 * IMPORTANT!  The following code MUST be at the top and at code root level
 * before namespacing or any other code.  While it is not necessary to keep
 * this code it is necessary that it is present whenever endpoint validation
 * is registered as this is how Infusionsoft confirms the endpoint as valid.
 */
$headers = array();
foreach ($_SERVER as $key => $value) {
	if (substr($key, 0, 5) <> 'HTTP_') {
		continue;
	}
	$header           = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
	$headers[$header] = $value;
}
$notification = json_decode(file_get_contents('php://input'));
if (isset($headers['X-Hook-Secret'])){header('X-Hook-Secret: ' .
$headers['X-Hook-Secret'] . '');}
/**
 * End required code root
 */

I ran this :

/**
 * IMPORTANT!  The following code MUST be at the top and at code root level
 * before namespacing or any other code.  While it is not necessary to keep
 * this code it is necessary that it is present whenever endpoint validation
 * is registered as this is how Infusionsoft confirms the endpoint as valid.
 */
$headers = array();
foreach ($_SERVER as $key => $value) {
	if (substr($key, 0, 5) <> 'HTTP_') {
		continue;
	}
	$header           = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
	$headers[$header] = $value;
}
$notification = json_decode(file_get_contents('php://input'));
if (isset($headers['X-Hook-Secret'])){header('X-Hook-Secret: ' .
$headers['X-Hook-Secret'] . '');}
/**
 * End required code root
 */

session_start();

require_once '../vendor/autoload.php';

$infusionsoft = new \Infusionsoft\Infusionsoft(array(
	'clientId' => '<clientId>',
	'clientSecret' => '<clientSecret>',
	'redirectUri' => '<url>',
));

// In order to verify the endpoint, we need to return the X-Hook-Secret header.
// By default, the autoverify() function will set the proper header, but if you
// pass false as the first argument to autoverify(false) the function will simply
// return the header value for you to set as you please (handy if you are using
// a PHP class or framework that manages requests for you

$infusionsoft->resthooks()->autoverify();

return;

But still is :
[{"key":"7","eventKey":"invoice.payment.add","hookUrl":"https://www.mydomain.com/is-hook.php","status":"Unverified"},{"key":"3","eventKey":"invoice.payment.add","hookUrl":"https://www.mydomain.com/is-hook.php","status":"Unverified"},{"key":"1","eventKey":"invoice.payment.add","hookUrl":"http://infusionsoft.app/verifyRestHook.php","status":"Unverified"},{"key":"5","eventKey":"invoice.payment.add","hookUrl":"https://www.mydomain.com/is-hook.php","status":"Unverified"}]

You have to re-validate. Just running the code won’t do it. that code is there so that when you setup the webhook, IS will see the endpoint as valid

You mean I got to run resthookManager.php again , right ?
Does the code you supplied need to be there in resthookManager.php ?

$headers = array();
...
$headers['X-Hook-Secret'] . '');}

Also,

	$resthook = $resthooks->create([
		'eventKey' => 'invoice.payment.add',
		# 'hookUrl' => 'http://infusionsoft.app/verifyRestHook.php'
        'hookUrl' => 'https://www.mydomain.com/is-hook.php'
	]);

is-hook.php is

<?php
$data = file_get_contents('php://input');
$to = 'me@gmail.com';
$subject = 'InfusionSoft Hook';
$message = $data;
@mail($to, $subject, $message);
?>

I got the email with the json data

{"event_key":"invoice.payment.add","verification_key":"xxx-xxxx-xxx-xxx-xxx"}

I don’t get what I’m doing wrong.

I did get one verified

{"key":"13","eventKey":"invoice.payment.add","hookUrl":"https://www.domain.com/is-hook.php","status":"Verified"}
1 Like