Webhooks...

89 views
Skip to first unread message

Zuminez

unread,
Oct 27, 2011, 8:30:25 PM10/27/11
to FreshBooks API
I'm a bit new to PHP, LIBCURL and HTML. I can't seem to figure out how
to handle Freshbook's posts to my webhooks page. I know how to send a
post from one webpage to another on the same server, but it doesn't
seem to work when receiving a post from Freshbooks.
Everything works fine, except when I need to use the line
$_POST["......."]; which I don't get anything from.
Please help if you can. Below is the code used up to the point of not
working....


part of....
Freshbooks_API.php
[code]
function _requestFreshbooksResponse($request, $URL, $token,
$userAgent)
{
//$request Your request in xml format.
//returns An xml response from freshbooks.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_USERPWD, $token);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/
xml"));

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);

$response = curl_exec($ch);
curl_close($ch);
return $response
}
[/code]


createWebhook.php
[code]
<?php
require_once('Freshbooks_API.php');

$request = '
<?xml version="1.0" encoding="utf-8"?>
<request method="callback.create">
<callback>
<event>client.update</event>
<uri>http://www.XXXXXXXXX.com/webhooks.php</uri>
</callback>
</request>
';

$URL = "https://XXXXXXXXX.freshbooks.com/api/2.1/xml-in";
$token = "XXXXXXXXXXXXXXXXXXX:X";

$userAgent = "XXXXXXX";

$response = getFreshbooksResponse($request, $URL, $token, $userAgent);
?>
[/code]




webhooks.php
[code]
<?php
$method = $_POST["name"];
$object_id = $_POST["object_id:"];
$verifier = $_POST["verifier:"];
$system = $_POST["system:"];
$user_id = $_POST["user_id:"];

$testFile = "testFile.txt";
$fHandle = fopen($testFile, "w");

fwrite($fHandle, $method . "\n");
fwrite($fHandle, $object_id . "\n");
fwrite($fHandle, $verifier . "\n");
fwrite($fHandle, $system . "\n");
fwrite($fHandle, $user_id . "\n");
fwrite($fHandle, "Hello");
fclose($fHandle);

?>
[/code]

I may need to use LibCurl somehow to receive posts from another
webserver, but if that's the case, I have no clue how to do it. All
the tutorials out there are terrible or non-existent.

Collège Maisonneuve

unread,
Dec 2, 2014, 3:52:15 PM12/2/14
to freshbo...@googlegroups.com
I have the exact same problem ... No solution ???
Reply all
Reply to author
Forward
0 new messages