Post

2 followers Follow
0
Avatar

Hooks - Use a function that's required an authentication ?

Hi,

I'm trying to active hooks to syncronise directly invoice from Podio to our system.
I'm blocked because I try to use this code .

It's seem that connection is required but... this code is called by the hook...
How can I do that ?

if(Podio::authenticate_with_app('ID APP', 'APP KEY')){

switch ($_POST['type']) {
case 'item.create':
$oInvoice = PodioItem::get($_POST['item_id']); // get complete Podio object
PodioInvoiceGenerator::generateInvoice($oInvoice); // create our invoice

break;
case 'item.update':
$oInvoice = PodioItem::get($_POST['item_id']); // get complete Podio object
PodioInvoiceGenerator::generateInvoice($oInvoice); // update invoice
break;
case 'item.delete':
$oInvoiceEmu = PodioInvoice::getInvoiceByPodioId($_POST['item_id']); // get our invoice
$oInvoiceEmu->delete(); // delete invoice
break;
}
}
else {
Log::error('connection with app fail ');

}

 

 

Caniche - Mathieu Bazelaire

Please sign in to leave a comment.

2 comments

0
Avatar

If would be great if someone post an example with other stuff than "just store information" from the post's hook ;)

#needhelp :)

 

 

Caniche - Mathieu Bazelaire 0 votes
1
Avatar

For information, I found somes errors...

Here is the final code for example.
If it helps someone...

//Podio::$debug = true;

Podio::setup(PodioConfig::APPKEY, PodioConfig::APPSECRET);

try {
Podio::authenticate('app', array('app_id' => $iApp, 'app_token' => $iAppToken)); // looks better
   switch ($_POST['type']) {
case 'hook.verify':
PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code'])); // validate the hook
break;

case 'item.create':
$oInvoice = PodioItem::get($_POST['item_id']);
if($oInvoice) {
// You got the object. Do something. 
}
break;

case 'item.update':
$oInvoice = PodioItem::get($_POST['item_id']);
if($oInvoice){
// you got the object. Do something.
}
break;

case 'item.delete':
// ...
break;
}

} catch ( PodioError $e ) {
Log::error('hook fail ' . print_r($e,true));
}
Caniche - Mathieu Bazelaire 1 vote