Skill Tracer
Skills › Scientific Agent Skills › pyzotero › read-api.md

read-api.md

146 lines · skills/pyzotero/references/read-api.md at 5f2bc03

Open on GitHub
1# Read API Methods
2

Read API Methods

Raw lines 1 to 2
3## Retrieving Items
4
5```python
6# One page of items (100 per call by default; excludes trash)
7items = zot.items()
8
9# Top-level items only (excludes attachments/notes that are children)
10top = zot.top(limit=25)
12# A specific item by key
13item = zot.item('ITEMKEY')
15# Up to 50 specific items in ONE request
16subset = zot.items(itemKey=','.join(['KEY1', 'KEY2', 'KEY3']))
17# get_subset([...]) instead makes one single-item request per key (up to 50).
19# Items from trash
20trash = zot.trash()
22# Deleted items (requires 'since' parameter)
23deleted = zot.deleted(since=1000)
25# Items from "My Publications"
26pubs = zot.publications() # user libraries only
28# Count all items
29count = zot.count_items()
31# Count top-level items
32n = zot.num_items()
33```

Retrieving Items

# One page of items (100 per call by default; excludes trash)
items = zot.items()

# Top-level items only (excludes attachments/notes that are children)
top = zot.top(limit=25)

# A specific item by key
item = zot.item('ITEMKEY')

# Up to 50 specific items in ONE request
subset = zot.items(itemKey=','.join(['KEY1', 'KEY2', 'KEY3']))
# get_subset([...]) instead makes one single-item request per key (up to 50).

# Items from trash
trash = zot.trash()

# Deleted items (requires 'since' parameter)
deleted = zot.deleted(since=1000)

# Items from "My Publications"
pubs = zot.publications()  # user libraries only

# Count all items
count = zot.count_items()

# Count top-level items
n = zot.num_items()
Raw lines 3 to 34
35## Item Data Structure
37Items are returned as dicts. Data lives in `item['data']`:
39```python
40item = zot.item('VDNIEAPH') # a dict, not a one-element list
41title = item['data'].get('title', '')
42item_type = item['data']['itemType']
43creators = item['data'].get('creators', [])
44tags = item['data']['tags']
45key = item['data']['key']
46version = item['data']['version']
47collections = item['data']['collections']
48doi = item['data'].get('DOI', '')
49```

Item Data Structure

Items are returned as dicts. Data lives in item['data']:

item = zot.item('VDNIEAPH')  # a dict, not a one-element list
title = item['data'].get('title', '')
item_type = item['data']['itemType']
creators = item['data'].get('creators', [])
tags = item['data']['tags']
key = item['data']['key']
version = item['data']['version']
collections = item['data']['collections']
doi = item['data'].get('DOI', '')
Raw lines 35 to 50
51## Child Items
53```python
54# Get child items (notes, attachments) of a parent
55children = zot.children('PARENTKEY')
56```

Child Items

# Get child items (notes, attachments) of a parent
children = zot.children('PARENTKEY')
Raw lines 51 to 57
58## Retrieving Collections
60```python
61# One page of collections (including subcollections)
62collections = zot.collections()
64# Top-level collections only
65top_collections = zot.collections_top()
67# A specific collection
68collection = zot.collection('COLLECTIONKEY')
70# Sub-collections of a collection
71sub = zot.collections_sub('COLLECTIONKEY')
73# All collections and sub-collections in a flat list
74all_cols = zot.all_collections()
75# Or from a specific collection down:
76all_cols = zot.all_collections('COLLECTIONKEY')
78# Items in a specific collection (not sub-collections)
79col_items = zot.collection_items('COLLECTIONKEY')
81# Top-level items in a specific collection
82col_top = zot.collection_items_top('COLLECTIONKEY')
84# Count items in a collection
85n = zot.num_collectionitems('COLLECTIONKEY')
86```

Retrieving Collections

# One page of collections (including subcollections)
collections = zot.collections()

# Top-level collections only
top_collections = zot.collections_top()

# A specific collection
collection = zot.collection('COLLECTIONKEY')

# Sub-collections of a collection
sub = zot.collections_sub('COLLECTIONKEY')

# All collections and sub-collections in a flat list
all_cols = zot.all_collections()
# Or from a specific collection down:
all_cols = zot.all_collections('COLLECTIONKEY')

# Items in a specific collection (not sub-collections)
col_items = zot.collection_items('COLLECTIONKEY')

# Top-level items in a specific collection
col_top = zot.collection_items_top('COLLECTIONKEY')

# Count items in a collection
n = zot.num_collectionitems('COLLECTIONKEY')
Raw lines 58 to 87
88## Retrieving Tags
90```python
91# All tags in the library
92tags = zot.everything(zot.tags())
94# Tags from a specific item
95item_tags = zot.item_tags('ITEMKEY')
97# Tags in a collection
98col_tags = zot.collection_tags('COLLECTIONKEY')
99```

Retrieving Tags

# All tags in the library
tags = zot.everything(zot.tags())

# Tags from a specific item
item_tags = zot.item_tags('ITEMKEY')

# Tags in a collection
col_tags = zot.collection_tags('COLLECTIONKEY')
Raw lines 88 to 100
101## Retrieving Groups
103```python
104# Use a client initialized with the USER ID, not a group ID.
105groups = zot.everything(zot.groups())
106# /users/{userID}/groups: inspect each group's access before writing.
107```

Retrieving Groups

# Use a client initialized with the USER ID, not a group ID.
groups = zot.everything(zot.groups())
# /users/{userID}/groups: inspect each group's access before writing.
Raw lines 101 to 108
109## Version Information
111```python
112# Last modified version of the library
113version = zot.last_modified_version()
115# Item versions dict {key: version}
116item_versions = zot.item_versions()
118# Collection versions dict {key: version}
119col_versions = zot.collection_versions()
121# Changes since a known version (for syncing)
122changed_items = zot.item_versions(since=1000)
123```

Version Information

# Last modified version of the library
version = zot.last_modified_version()

# Item versions dict {key: version}
item_versions = zot.item_versions()

# Collection versions dict {key: version}
col_versions = zot.collection_versions()

# Changes since a known version (for syncing)
changed_items = zot.item_versions(since=1000)
Raw lines 109 to 124
125## Library Settings
127```python
128settings = zot.settings()
129# Returns a setting-name mapping; values carry version and value.
130# Available settings depend on the library; do not assume a fixed set.
131# Use 'since' to get only changes:
132new_settings = zot.settings(since=500)
133```

Library Settings

settings = zot.settings()
# Returns a setting-name mapping; values carry version and value.
# Available settings depend on the library; do not assume a fixed set.
# Use 'since' to get only changes:
new_settings = zot.settings(since=500)
Raw lines 125 to 134
135## Saved Searches
137```python
138searches = zot.searches()
139# Retrieves saved search metadata (not results)
140```

Saved Searches

searches = zot.searches()
# Retrieves saved search metadata (not results)
Raw lines 135 to 141
142## Endpoint and Sync Boundaries
144All library routes use `/users/{userID}` or `/groups/{groupID}` under `https://api.zotero.org`. Item reads use `/items`, `/items/top`, `/items/trash`, `/items/{key}`, and `/items/{key}/children`. Collections use `/collections`, `/collections/top`, `/collections/{key}`, `/collections/{key}/collections`, and `/collections/{key}/items[/top]`. Tags use `/tags`, `/items/{key}/tags`, or `/collections/{key}/tags`. `settings()`, `searches()`, and `deleted(since=...)` use the corresponding library routes. `publications()` uses `/users/{userID}/publications/items`.
146`deleted()` returns a dict of deleted keys grouped by object type, not item records. A complete incremental sync needs changed objects **and** deletions, plus `includeTrashed=1` when tracking trash transitions. Save the library version from the completed read sequence, not a later unrelated call; restart/reconcile if versions change during pagination. See [official syncing rules](https://www.zotero.org/support/dev/web_api/v3/syncing). `last_modified_version()` makes its own multi-object read.

Endpoint and Sync Boundaries

All library routes use /users/{userID} or /groups/{groupID} under https://api.zotero.org. Item reads use /items, /items/top, /items/trash, /items/{key}, and /items/{key}/children. Collections use /collections, /collections/top, /collections/{key}, /collections/{key}/collections, and /collections/{key}/items[/top]. Tags use /tags, /items/{key}/tags, or /collections/{key}/tags. settings(), searches(), and deleted(since=...) use the corresponding library routes. publications() uses /users/{userID}/publications/items.

deleted() returns a dict of deleted keys grouped by object type, not item records. A complete incremental sync needs changed objects and deletions, plus includeTrashed=1 when tracking trash transitions. Save the library version from the completed read sequence, not a later unrelated call; restart/reconcile if versions change during pagination. See official syncing rules. last_modified_version() makes its own multi-object read.

Raw lines 142 to 146