I am trying to get a response from the Exact Online API webhook subscription. This requires that the callback URL is https. Normal GET and POST requests to Exact return XML responses, and my site has no problem receiving these, whether the callback I specify is http or https. On submitting the webhook subscription request, I should get a 200 response as part of the JSON body posted by Exact Online.

I do not see this, but believe that the webhook is correctly created because if I resubmit the request, I get an 'Error: 500. Data already exists.' message, which means the webhook has been created. However, when I use file_get_contents('php://input') to get the response, an empty string is returned.

I read somewhere that the SSL certificate might be the cause (I cannot remember where I read this), and might be blocking the JSON payload. Is there any way that I can test to see whether it is the certificate setup which is causing the problem?

Initially, I created the webhook subscription with Picqer - file_get_contents('php://input') returned an empty string. If I resubmitted the request, I got the 'Error 500. Data already exists.' message.

Then, I submitted the subscription request using CURL (sending the callback url and Topic as JSON parameters in the header). I got a string response with a guid'#########' ID for the webhook subscription (i.e. for the webhook/WebhookSubscriptions endpoint), but still nothing for the data endpoint (given by the Topic field).

My Picqer code:

$subscription = new \Picqer\Financials\Exact\WebhookSubscription($connection);
$subscription->deleteSubscriptions();
$subscription->CallbackURL = $callback;
$subscription->Topic = $topic;
$subscription->save();
$input = file_get_contents('php://input');
var_dump($input);

I would expect to get JSON responses that I can access with file_get_contents('php://input'). Instead, I get string(0)"". When I tried print_r($_POST), I got Array().

Is there anything else I can try?

1 Answers

0
AndyG On

My webhook was working perfectly. As the code at the callback URL runs automatically, using var_dump($input) is not a sensible way to see the output. I replaced it with the following:

// var_dump($input);
// Replaced the above with:
$fp = fopen('MyWHLogs.txt', 'w');
fwrite($fp, $input);
fclose($fp);

I can now look at MyWHLogs.txt to see the webhook response.