Post

1 follower Follow
0
Avatar

Web Hooks: no item_id from item.create?

Hello!

First time working with the Podio API. I'm trying to create a simple script that adds the current date and time to a newly created item. If I manually add in the item ID (# instead of $_POST['item_id']), it works, but the code below does nothing. Can anyone spot my error or lend advice?

date_default_timezone_set('America/New_York');

require_once('PodioAPI.php');

$client_id = "custom-podio-operations-gmideas";

$client_secret = "###";

ini_set('display_errors', '1');

// Setup client

Podio::setup($client_id, $client_secret);

switch ($_POST['type']) {

case 'hook.verify':

// Validate the webhook

PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code']));

case 'item.create':

PodioItem::update($_POST['item_id'], array('fields' => array(

"date" => array('start' => date("Y-m-d H:i:s"), "end" => date("Y-m-d H:i:s"))

)));

// Do something. item_id is available in $_POST['item_id']

case 'item.update':

// Do something. item_id is available in $_POST['item_id']

case 'item.delete':

// Do something. item_id is available in $_POST['item_id']

}

Davin Green Answered

Please sign in to leave a comment.

5 comments

0
Avatar

Hi Davin,

Set up some logging so that you can store the $_POST received on each page request. Then you can see exactly what data you are getting. It will probably also help to get the php client into debug mode while you are developing so you can see exactly what API requests are being made. See more https://github.com/podio/podio-php#debugging--error-handling

/Andreas

Andreas Haugstrup Pedersen 0 votes
0
Avatar

Hey Andreas,

Is there a reference you can point me to that gives a complete PHP web hook example? I'm finding it very hard to find a full example to refer to as I work with this. The API documentation only gives these things piece-wise

Thanks!

Davin Green 0 votes
0
Avatar

Just this: https://developers.podio.com/examples/webhooks 

I suspect your POST data isn't being populated properly (thus the need for debugging to happen), or the hook endpoint isn't hit at all (could be a bad URL when creating the hook, could be validation that fails). You need to get debugging to solve those issues.

Andreas Haugstrup Pedersen 0 votes
0
Avatar

I'd like to make sure this setup is correct at all, but I don't have a complete example to reference. Is there code you can point me to that represents an entire php file for web hook integration?

The API only has this. It doesn't tell me if my authentication is right, if I need auth at all with a verified webhook, etc. It would be very helpful to have a more complete example.

switch ($_POST['type']) {
case 'hook.verify':
// Validate the webhook
PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code']));
case 'item.create':
// Do something. item_id is available in $_POST['item_id']
case 'item.update':
// Do something. item_id is available in $_POST['item_id']
case 'item.delete':
// Do something. item_id is available in $_POST['item_id']
}

Davin Green 0 votes
0
Avatar

Hey Davin,

You always need to run Podio::setup() before doing anything. If you don't you'll get an exception when making your first API call (look in your PHP error log).

Hook validation can be done without authentication. It's marked as a "Public" operation in the API reference: https://developers.podio.com/doc/hooks/validate-hook-verification-215241 

All other API calls require authentication. Otherwise there's no way to determine if you have permissions to do what you want to do.

So you can add Podio::setup() and Podio::authenticate() to the top of what you pasted in and you'll be good. But get the client into debug mode and also start logging exactly what your script is receiving. Then you can see what's actually going wrong. Your server could not be populating the POST array or the verification could fail. Until you start looking at potential error messages there's no way of knowing.

Does that help?

/Andreas

Andreas Haugstrup Pedersen 0 votes