Why is this object NULL? [podio API in PHP]

103 Views Asked by At

I am working with the Podio API, here is my code:

Podio::setup($client_id, $client_secret);
Podio::authenticate_with_app($app_id, $app_token);
$items = PodioItem::filter($app_id);

print "My app has ".count($items)." items<br><br>";
foreach($items as $item){
    print $item->fields['First']->values; //THIS IS LINE 42
    print $item->fields['Last']->values; //THIS IS LINE 43
}

This is what it returns:

My app has 2 items


Notice: Trying to get property of non-object in C:\xampp\htdocs\PodioAPITesting\testPodioAPI.php on line 42

Notice: Trying to get property of non-object in C:\xampp\htdocs\PodioAPITesting\testPodioAPI.php on line 43

Notice: Trying to get property of non-object in C:\xampp\htdocs\PodioAPITesting\testPodioAPI.php on line 42

Notice: Trying to get property of non-object in C:\xampp\htdocs\PodioAPITesting\testPodioAPI.php on line 43



Fatal error: Uncaught exception 'PodioDataIntegrityError' with message 'Field must have id or external_id set.' in C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\models\PodioFieldCollection.php:31 Stack trace: #0 C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\models\PodioItemFieldCollection.php(48): PodioFieldCollection->offsetSet(NULL, Object(PodioTextItemField)) #1 C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\lib\PodioCollection.php(16): PodioItemFieldCollection->offsetSet(NULL, Object(PodioTextItemField)) #2 C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\models\PodioFieldCollection.php(15): PodioCollection->__construct(Array) #3 C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\models\PodioItemFieldCollection.php(36): PodioFieldCollection->__construct(Array) #4 C:\xampp\htdocs\PodioAPITesting\testPodioAPI.php(53): PodioItemFieldCollection->__construct(Array) #5 {main} thrown in C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\models\PodioFieldCollection.php on line 31

(I have marked above which lines are lines 42 and 43)

after playing around with the code I discovered that $item->fields['First'] is NULL (therefore I would assume that $item->fields['Last'] is also NULL. But I'm not sure why this is, I know for a fact that this app has fields called 'First' and 'Last', and that these fields have data in them.

Does anyone know what's going on here?

1

There are 1 best solutions below

0
On

I have worked with podio api in C#, so my understanding of you code might be wrong, so what I understand here is, print $item->fields['First']->values; tries to get field value of field First, now if you are trying to pass external id of the field here, you are passing it wrong because field external Id always starts with lower case letter, which means this should look like

$item->fields['first']

you can find this external Id in developer option of that App