Post

2 followers Follow
0
Avatar

[PHP] How do I display a list of item ID's?

Hello, I'm trying to see if I can just display a list of items in an app. I've got authentication working it seems, so my problem may have something to do with my limited programming knowledge.

So here's my code:

$items = $api->item->getItems($app_id, array('limit'=>20));

foreach ($items as $item ){

echo $item['item_id'];

}

and i'm receiving error "Notice: Undefined index: item_id in .../index.php on line 46"

Could someone help me get on the right track?

Zak Lampert Answered

Please sign in to leave a comment.

10 comments

0
Avatar

Thanks for the help, I now have:

$items = $api->item->getItems($app_id, array('limit'=>20))['items'];

 foreach ($items as $item){

$item_id = $item['item_id'];

echo 'The item id is' . $item_id;

echo '<br/>';

}

}

 

And am getting a list of 20 item ID's. 

I am now trying get the field data for one of the fields in the item, but am at a loss. If there are examples of this, I can't seem to find any.

Zak Lampert 0 votes
Comment actions Permalink
0
Avatar

So in Java I did this - you can translate:

 

    Item item = new ItemAPI(resourceFactory).getItem(16390641);

    List<FieldValuesView> fields = item.getFields();

    for (FieldValuesView field : fields)

    {

        

        System.out.println(field.getLabel().toString());

        System.out.println(field.getValues().toString());

        

    }

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

Thanks, Rich. I'm not familiar enough with Java or the API to be able to translate to PHP, but it's only my first afternoon with this API. I'm sorta new at this and am basically just trying it out for fun. 

I'd still love to see an example of displaying field values in PHP.

Zak Lampert 0 votes
Comment actions Permalink
0
Avatar

Hey Zak,

Just do a print_r() on the item and you'll see the structure. It's just one giant array you can work with. In your case you'll want to loop over $item['fields'] until you find the field you are looking for.

Andreas Haugstrup Pedersen 0 votes
Comment actions Permalink
0
Avatar

Seems a little janky but 

$description = $item['fields'][1]['values'][0]['value']; 

Gave me my field "description". 

Zak Lampert 0 votes
Comment actions Permalink
0
Avatar

Hey Zach and Andreas. I just run into this post looking for something similar when working with item_ids.

Im currently working on a project that requires updating an item in one of our apps that matches a string, that is a variable that we get on an external application, which happens to be an unique key/id. I have been using the API and php client. I know i have to use the update function, but i dont know how to get the item id of the item that includes the string im looking for to make the update work. Any advice? Is that possible? 

I´m not a professional coder, so any help would be highly appreciated.

Sergio Giraldo 0 votes
Comment actions Permalink