Search code examples
phppodio

Podio PHP API - Filter item collection by calculated field value


I have a calculated field with external id has-email which populates with the value 1 if the item's email address is not empty (and 0 if it is).

$filters = array (
    'has-email' => 1
);

$attributes = array (
    'filters'       => $filters
);

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

I'm trying to get a collection of items which includes only those with an email address (where the value of has-email is 1), however, this returns the error Podio Error Invalid value 1 (integer): must be object. How can I filter on calculated field value?


Solution

  • You should pass the value as an array with from and to keys. Also please make sure the Calculation field has-email's value in Podio is a number(not a string).

    The below code will return the items where the value of has-email is 1

    $filters = array(
        'has-email' => array(
            'from' => 1,
            'to' => 1
        )
    );
    

    and the below code will return the items where the value of has-email is 0

    $filters = array(
        'has-email' => array(
            'from' => 0,
            'to' => 0
        )
    );