Post

4 followers Follow
1
Avatar

PHP client filterItems() by date range

Dear all

Im trying to receive some items from a specific application based on a date range (start dates of the item).

Ive been trying a lot of options with filters for the filterItems() method bu without any luck.

$app_id = APP_ID;

$field_id = "date";

$filters = array(

'key' => $field_id,

array(

'values' => array(

'from' => '2012-11-14',

'to' => '2012-11-17'

)

)

);

$items = $api->item->filterItems($app_id, $filters);

The API returns all items in the app, but a haven't had any luck with the date-range filtering.

Would be a great help of someone could point me in the right direction :)

Anders Hojmose Answered

Please sign in to leave a comment.

6 comments

0
Avatar

Hi Anders,

You need to send a bit different data-structure to the API when filtering. This is an example of the API communication needed:

POST http://api.podio.com/item/app/2225/filter/

Body:

{

"limit": 13,

"filters": {

"created_on": {

"to": "2012-11-29",

"from": "2012-11-08"

}

}

}

So in PHP you would need to something like:

$body = array(

'filters' => array(

'created_on' => array(

'to' => '2012-11-29',

'from' => '2012-11-29'

)

)

);

Hope it clarified things a bit.

//Kenneth Auchenberg

Developer, Podio

Kenneth Auchenberg 0 votes
0
Avatar

Thanks Kenneth - that helped a lot!

If anyone else is interested, this seems to do the job:

$app_id = APP_ID;

$field_id = "datefield"; // External ID of field to apply date filter

$body = array(

'filters' => array(

$field_id => array(

'from' => '2012-11-01',

'to' => '2012-11-13'

)

),

limit => 6

);

$items = $api->item->filterItems($app_id, $body);

Anders Hojmose 0 votes
0
Avatar

Trying to do the same thing here and I'm not getting any items back ( I'm using the old PHP client ).

I just created the 10th item in my app.

http://pastebin.com/YXQzR8yp

The code returns:

Array (    [filtered] => 0    [total] => 10    [items] => Array        (        ) )

So it's definitely the right app id because it's returning the "10" but it just can't filter out the brand new item I created.

Any ideas?

James Trusler 0 votes
0
Avatar

if i use this:

$app_id = '2561625';

$field_id = "19593751"; // External ID of field to apply date filter

$body = array(

    'filters' => array(

        $field_id => array(

            'from' => '2013-05-01',

            'to' => '2013-06-20'

        )

    )

    

);

$items = PodioItem::filter($app_id ,$body);

 

then i am getting this error:

 

Fatal error: Uncaught PodioBadRequestError: "Invalid value "2013-06-20" (string): must be integer"
Request URL: http://api.podio.com/item/app/2561625/filter/
Request Body: {"filters":{"19593751":{"to":"2013-06-20","from":"2013-05-01"}}}

Stack Trace:
#0 /var/www/podio/podio-php/lib/Podio.php(269): Podio::request('POST', '/item/app/25616...', Array, Array)
#1 /var/www/podio/podio-php/models/PodioItem.php(91): Podio::post('/item/app/25616...', Array)
#2 /var/www/podio/pdio.php(121): PodioItem::filter('2561625', Array)
#3 {main}
thrown in /var/www/podio/podio-php/lib/Podio.php on line 206

What is the prob?

Samiul 0 votes
0
Avatar

What happens when you change $app_id and $field_id to be integers instead of strings?

Andreas Haugstrup Pedersen 0 votes