urschrei / pyzotero

Pyzotero: a Python client for the Zotero API
https://pyzotero.readthedocs.org
Other
908 stars 99 forks source link

retrieving items from subcollections #141

Closed sdaza closed 3 years ago

sdaza commented 3 years ago

Thanks for your nice package.

I am trying to get all the items from a collection (including subcollections). According to the documentation:

Zotero.collection_items(collectionID[, search/request parameters]) Returns items from the specified collection. This includes sub-collection items

But, when I useitems = zot.collection_items("NFWFUHKR"),items is empty. According to the Zotero API documentation:

<userOrGroupPrefix>/collections/<collectionKey>/items | Items within a specific collection in the library

urschrei commented 3 years ago

It looks like this is an error in the documentation. One way to do this would be to retrieve all collections for a given collection key:

ac = zot.all_collections(collid='NFWFUHKR'), then [zot.collection_items(c['key']) for c in ac] Which will give you a list of lists, each containing the collection items (this includes sub-items such as attachments etc – you'd need to call collection_items_top if you only wanted top-level items in each collection) in each subcollection (including 'NFWFUHKR')

sdaza commented 3 years ago

thanks, yes, I am doing that: list of lists!