Search code examples
phppodio

I fetch data from podio CRM using PHP


I fetch data from podio CRM using PHP language and I fetch data for each element via its id as it is found in this function:

public function getContacts($item_id) {

    $this->contactAuth();

    $item = \PodioItem::get_by_app_item_id($podio_contact_app_id,$item_id);
      return $item;
}

For example we have the 'Status' we show it like this:

$status = $item->fields[6]->values; 

Not all elements get it right though it is the same function.

Sometimes :

$status = $item->fields[6]->values;

and sometimes :

$status = $item->fields[8]->values;

Can we know what caused the problem?


Solution

  • If some fields are empty they will not be presented in the PodioItem object, that is why the position of a particular field in the array may vary (like a Status field in your example).

    So instead of using a field index (which may vary), you should get the value from a field by field's External ID (a human readable name like 'title', 'status' etc) or Field ID (a numeric code):

    $item->fields['title']->values        // 'title' is an External ID
    $item->fields->get(123456789)->values // 123456789 is a Field ID
    

    To know what External ID and Field ID are for a particular field you can list all fields like this:

    // Iterate over the field collection
    foreach ($item->fields as $field) {
      // You can now work on each individual field object:
      print "This field has the id: ".$field->field_id;
      print "This field has the external_id: ".$field->external_id;
    }
    

    Or you can see developer's info on all fields right in Podio in App menu → Developer

    enter image description here

    And anyways, check the Podio PHP wrapper documentation at https://podio-community.github.io/podio-php/items/ it is pretty useful:)