Search code examples
phppodio

Get file_ids subarray from PodioItem::get


I'm trying to download all the files attached to a particular item, but I'm having trouble accessing the file_ids subarray from the returned item object. I'm able to access pretty much every other part of it, like item_id, but for some reason, when I try to fetch anything from file_ids it returns nothing.

$item = PodioItem::get( ######### );

//this works
print $item;
//this works
print "item_id is: ".$item->item_id."\n";
//this returns 0, should return 20
print "file_ids count: ".count($item->file_ids)."\n";
//this returns nothing, should return a file_id
print "file_ids[0] is: ".$item->file_ids[0]."\n"; 

Here's the output:

> Array (
>     [item_id] => #########
>     [external_id] => share_#########
>     

>     .
>     .
>     .
> 
>     [file_ids] => Array
>         (
>             [0] => #########
>             [1] => #########
>             [2] => #########
>             [3] => #########
>             [4] => #########
>             [5] => #########
>             [6] => #########
>             [7] => #########
>             [8] => #########
>             [9] => #########
>             [10] => #########
>         )

> 
> ) 

>item_id is: #########  
>file_ids count: 0  
>file_ids[0] is:

Any help would be greatly appreciated. I've been racking my brains and the internet as to why I can get everything but file_ids.


Solution

  • I don't see files_ids array in the response from API call to Podio. I use podio-php v4.3.0. PodioItem object has files property which is an object of type PodioCollection. You can just access its properties directly. For example:

    /** @var PodioItem $item */
    $item = PodioItem::get_by_app_item_id($appId, 1);
    /** @var PodioFile $curFile */
    foreach ($item->files as $curFile) {
        echo $curFile->name;
    }