Need a filtered list of items

Answered

Comments

11 comments

  • Casper Fabricius

    You have a total of 9 items, but set the offset to 20. That will give you back no items.

    Try setting offset to 0. Does that give you back the 9 items?

    0
    Comment actions Permalink
  • Kasper Tikjøb Andersen

    Silly me, just copied the filter example and never wondered what offset was - yes the list works now :-)

    Now i want to filter by item 37336550 which is type=state (external_id=test-status) - i only want items with one of the options, but no matter what i try $item_collection['filtered'] also return 9. What should i use in the filter (second) line?

    37336550 => 2

    0
    Comment actions Permalink
  • Casper Fabricius

    The state field is a deprecated field, which is why you won't find too much information about it. I don't know what the "2" is supposed to be, but as opposed to the category field that has replaced it, the state field doesn't use ids for the options, it uses plain text. Also these values must be given as an array.

    So something like this should work in your case, assuming you want to filter by a status called "open":

    37336550 => array('open')

    0
    Comment actions Permalink
  • Kasper Tikjøb Andersen

    Wonderful, that solved it :-D here's the example i would have loved to have found in your references ;-)

    <?

    // Load the module

    require_once('/usr/local/www/..../lib/PodioAPI.php');

    // Connect with API ID

    define("CLIENT_ID", "...");

    define("CLIENT_SECRET", "get from https://podio.com/settings/api");

    Podio::setup(CLIENT_ID, CLIENT_SECRET);

    // Authenticate with App ID

    define("APP_ID", "...");

    define("APP_TOKEN", "get from https://????.podio.com/???space???/apps/????appid???/hooks");

    Podio::authenticate('app', array('app_id' => APP_ID, 'app_token' => APP_TOKEN));

    // Get all matching items

    $item_collection = PodioItem::filter(4812770, array( // Retrieve items from this App ID

    'filters' => array(

    37414507 => array(1,2,3), // Only return from specific item id type=category (1., 2 and 3.) option set)

    37336550 => array('Fejl indrapporteret') // Only return from specific item id type=state (with specific text set)

    ),

    'limit' => 20, // Return max 20 items

    'sort_by' => 'created_on', // sort by creation date

    'sort_desc' => true, // sort by creation date

    'offset' => 0, // Always start at 0 position

    ));

    ?>

    <table>

    <thead>

    <th class="date">Date</th>

    <th class="address">Adress</th>

    <th class="zip">Zip</th>

    <th class="reason">Reason</th>

    <th class="status">Status</th>

    </thead>

    <tbody>

    <? foreach ($item_collection['items'] as $item) {

    $thedate = $item->field('observationsdato')->humanized_value();

    $datetime = date_create_from_format('Y-m-j H:i', $thedate); // d/M/Y:H:i:s

    $danishdate = date_format($datetime, 'j-m-Y H:i'); // Y-m-d H:i:s

    print "

    <tr>

    <td>{$danishdate}</td>

    <td>{$item->field('fejl-adresse2')->humanized_value()}</td>

    <td>{$item->field('fejl-postnr')->humanized_value()}</td>

    <td>{$item->field('lampefejl-uddybning')->humanized_value()}</td>

    <td>{$item->field('test-status')->humanized_value()}</td>

    </tr>";

    } ?>

    </tbody>

    </table>

    0
    Comment actions Permalink
  • Casper Fabricius

    Thanks for sharing :)

    0
    Comment actions Permalink
  • Victoria Aparicio

    Hello, I wan to know if it's possible to get all the items, thanks!

    0
    Comment actions Permalink
  • Andreas Garnæs

    Victoria, you cannot get all items at once (imagine if you had 1,000,000 items in an app). Instead you will need to go through the items in a paginated fashion using limit and offset, see Filter Items-endpoint.

    0
    Comment actions Permalink
  • Victoria Aparicio

    Ok, If I used limit and offset, how I can go to the next page? Could you please give me an example , thanks

    0
    Comment actions Permalink
  • Andreas Garnæs

    If you do the first request with limit 100 and offset 0, the second page would be a request with limit 100 and offset 100, the third page would be limit 100 and offset 200, etc.

    0
    Comment actions Permalink
  • Victoria Aparicio

    Hello Andreas, now I have a problem when I get the data using foreach. This is the error
    Error: Operation timed out after 30001 milliseconds with 0 bytes received

    0
    Comment actions Permalink
  • Andreas Garnæs

    Can you share a little about your use case? How many items are in your app? What request is failing?

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk