1

When using the Podio PHP API and after getting an item collection using:

$item_collection = PodioItem::filter( $app_id, $attributes );

How can I get the value(s) of a field with an external_id of, for example, email?

Currently I loop through all the items like this:

$items = [];
foreach ($item_collection as $item) {
    $email = "";
    foreach ( $item->fields as $field ) {                   
        if( $field->external_id == "email") {
            $email = trim($field->values);
        } //repeat for each field eg 'name'
    }
    $items[] = array (
        'email' => $email,
        'name'  => $name //etc
   );
}

Is there a way to directly get the field value without looping through all the fields in the whole collection of items?

Using PodioItem::get_field_value obviously makes another request which seems counter to getting all the items from PodioItem::filter.

James
  • 311
  • 5
  • 17
  • i dont know the Podio API, but i would assume that the "email" attribute is always on the same index, so you could acess it dirctly. Else you you could use `break` to stop the foreach-loop after you found the attribute for a small performance boost – fehrlich Aug 03 '17 at 09:08
  • Unfortunately, the index isn't the same for all items - if a particular item doesn't have a value for that field then it isn't returned. – James Aug 03 '17 at 09:18

1 Answers1

0

There is an direct api call is there, but unfortunately that method is not available in the client it seems. hope this urls help you. https://help.podio.com/hc/en-us/community/posts/200516418-Get-Field-Values-from-Item-by-external-id-PHP-

https://developers.podio.com/doc/items/get-item-by-external-id-19556702

priya lingam
  • 164
  • 4
  • Thanks, but I was trying to avoid making an additional api calls. I have all the item data (including fields) for all the items in the app in the `$item_collection` array (see code above). I'd like to know if there's a cleaner way to access the field data than looping through every field for every item in the collection. – James Aug 07 '17 at 09:11