Post

2 followers Follow
0
Avatar

How to filter items by a field label value

I want to filter items I am searching for by the value of a category field. I have the following code which obviously doesn't work hehe:

$oClients = PodioItem::filter( $appClients->appId, $attributes = array(
//"Organisation type" => "Client"
"organisation-type" => "Client"
) );

So I would like to return only the items where the 'Organisation type' field that I created equals the category "Client"

This is for the PHP API, any ideas?

 

James Trusler

Please sign in to leave a comment.

9 comments

0
Avatar

Am I on the right lines with this:

$oClients = PodioItem::filter(
$appClients->appId, array(
"filters" => array(
"organisation-type" => "Client"
//"Organisation type" => "Client"
)
)
);

obviously not working but can't find any examples.

James Trusler 0 votes
Comment actions Permalink
0
Avatar

Okay so I see now the field id in the developer part of Podio for the app.. I have placed that in,

$oClients = PodioItem::filter(
$appClients->appId, array(
"filters" => array(
"29445296" => "Client"
)
)
);

I also replaced the string "Client" for an integer 0 and 1, to see if it would reference the category value on key

James Trusler 0 votes
Comment actions Permalink
0
Avatar

Okay so I found the data-id part of the categories by using developer toolbar to inspect the category on an item. I assume there is a better way of doing this?

James Trusler 0 votes
Comment actions Permalink
0
Avatar

Is this the wrong technique for what I need, It's running awfully slow and im limited to receiving only 500 items?

$oClients = PodioItem::filter(
$appClients->appId, array(
"limit" => 1000,
"sort_desc" => TRUE,
"sort_by" => "title",
"filters" => array(
"29445296" => 2
)
)
);

As you can see, I want to filter my results by category. But I also may have thousands of items (clients) to return. I realise I can divide this job up into multiple calls but even the one call takes ages to run.

I then thought, well actually it doesn't matter so much if I do not filter the items by category, maybe it's faster without using filter (as a kind of compromise for performance) so I went to go do a "Get items" but found out that it is or will be deprecated.

So my question is how do I get this podio call to return maybe over 1000 results at a faster rate. The above call actually exceeded maximum run time for PHP loop on my server which is 90 seconds.

The actual data that I want back is simply one value.. the app item's id. but I instead get given every single value that is assigned to that item.

any ideas?

James Trusler 0 votes
Comment actions Permalink
0
Avatar

Hi James,

If you just need field ids or external ids for the fields of an app you can find them in the "Developer" section for the app (same place you setup webhooks). This doesn't show option ids for category fields, in that case I either use the Inspector like you did or use the API sandbox at the bottom here: https://developers.podio.com/doc/applications/get-app-22349

You are indeed limited to 500 items at the time. As you have noticed it does take quite a while, which is only fair considering the amount of data you're asking for. If you need to grab that many items I suggest that you grab 100 items at a time. You can use some sort of job queue so you can do the requests in parallel (something that's probably not so easy to do in PHP alone).

Even better would be to cache the results and only request items that have been changed since the last time your script ran. It's quite wasteful to get all items on every run.

You may also want to look into webhooks where you can get notified every time an item in an app changes.

There are almost always alternatives to fetching thousands of items.

/Andreas

Andreas Haugstrup Pedersen 0 votes
Comment actions Permalink
0
Avatar

That's fine. Thanks a bunch for the reply. I am generating a list of clients from a client app for a 'select' field... I was hoping that it would just work but instead, I'll do a series of async calls like you said... Shame i'm not using c#.NET, makes life a lot easier for this kind of thing. oh well.

James Trusler 0 votes
Comment actions Permalink
0
Avatar

A select box with a thousand entries sounds overwhelming to me. Have you considering using an autocomplete text field instead? They are usually much better at handling a massive amount of choices.

/Andreas

Andreas Haugstrup Pedersen 0 votes
Comment actions Permalink
0
Avatar

Even better would be to cache the results and only request items that have been changed since the last time your script ran.
How do i do this?

JD 0 votes
Comment actions Permalink