references/read-api.md
4.3 KB查看排版效果| 1 | # Read API Methods |
| 2 | |
| 3 | ## Retrieving Items |
| 4 | |
| 5 | ```python |
| 6 | # One page of items (100 per call by default; excludes trash) |
| 7 | items = zot.items() |
| 8 | |
| 9 | # Top-level items only (excludes attachments/notes that are children) |
| 10 | top = zot.top(limit=25) |
| 11 | |
| 12 | # A specific item by key |
| 13 | item = zot.item('ITEMKEY') |
| 14 | |
| 15 | # Up to 50 specific items in ONE request |
| 16 | subset = zot.items(itemKey=','.join(['KEY1', 'KEY2', 'KEY3'])) |
| 17 | # get_subset([...]) instead makes one single-item request per key (up to 50). |
| 18 | |
| 19 | # Items from trash |
| 20 | trash = zot.trash() |
| 21 | |
| 22 | # Deleted items (requires 'since' parameter) |
| 23 | deleted = zot.deleted(since=1000) |
| 24 | |
| 25 | # Items from "My Publications" |
| 26 | pubs = zot.publications() # user libraries only |
| 27 | |
| 28 | # Count all items |
| 29 | count = zot.count_items() |
| 30 | |
| 31 | # Count top-level items |
| 32 | n = zot.num_items() |
| 33 | ``` |
| 34 | |
| 35 | ## Item Data Structure |
| 36 | |
| 37 | Items are returned as dicts. Data lives in `item['data']`: |
| 38 | |
| 39 | ```python |
| 40 | item = zot.item('VDNIEAPH') # a dict, not a one-element list |
| 41 | title = item['data'].get('title', '') |
| 42 | item_type = item['data']['itemType'] |
| 43 | creators = item['data'].get('creators', []) |
| 44 | tags = item['data']['tags'] |
| 45 | key = item['data']['key'] |
| 46 | version = item['data']['version'] |
| 47 | collections = item['data']['collections'] |
| 48 | doi = item['data'].get('DOI', '') |
| 49 | ``` |
| 50 | |
| 51 | ## Child Items |
| 52 | |
| 53 | ```python |
| 54 | # Get child items (notes, attachments) of a parent |
| 55 | children = zot.children('PARENTKEY') |
| 56 | ``` |
| 57 | |
| 58 | ## Retrieving Collections |
| 59 | |
| 60 | ```python |
| 61 | # One page of collections (including subcollections) |
| 62 | collections = zot.collections() |
| 63 | |
| 64 | # Top-level collections only |
| 65 | top_collections = zot.collections_top() |
| 66 | |
| 67 | # A specific collection |
| 68 | collection = zot.collection('COLLECTIONKEY') |
| 69 | |
| 70 | # Sub-collections of a collection |
| 71 | sub = zot.collections_sub('COLLECTIONKEY') |
| 72 | |
| 73 | # All collections and sub-collections in a flat list |
| 74 | all_cols = zot.all_collections() |
| 75 | # Or from a specific collection down: |
| 76 | all_cols = zot.all_collections('COLLECTIONKEY') |
| 77 | |
| 78 | # Items in a specific collection (not sub-collections) |
| 79 | col_items = zot.collection_items('COLLECTIONKEY') |
| 80 | |
| 81 | # Top-level items in a specific collection |
| 82 | col_top = zot.collection_items_top('COLLECTIONKEY') |
| 83 | |
| 84 | # Count items in a collection |
| 85 | n = zot.num_collectionitems('COLLECTIONKEY') |
| 86 | ``` |
| 87 | |
| 88 | ## Retrieving Tags |
| 89 | |
| 90 | ```python |
| 91 | # All tags in the library |
| 92 | tags = zot.everything(zot.tags()) |
| 93 | |
| 94 | # Tags from a specific item |
| 95 | item_tags = zot.item_tags('ITEMKEY') |
| 96 | |
| 97 | # Tags in a collection |
| 98 | col_tags = zot.collection_tags('COLLECTIONKEY') |
| 99 | ``` |
| 100 | |
| 101 | ## Retrieving Groups |
| 102 | |
| 103 | ```python |
| 104 | # Use a client initialized with the USER ID, not a group ID. |
| 105 | groups = zot.everything(zot.groups()) |
| 106 | # /users/{userID}/groups: inspect each group's access before writing. |
| 107 | ``` |
| 108 | |
| 109 | ## Version Information |
| 110 | |
| 111 | ```python |
| 112 | # Last modified version of the library |
| 113 | version = zot.last_modified_version() |
| 114 | |
| 115 | # Item versions dict {key: version} |
| 116 | item_versions = zot.item_versions() |
| 117 | |
| 118 | # Collection versions dict {key: version} |
| 119 | col_versions = zot.collection_versions() |
| 120 | |
| 121 | # Changes since a known version (for syncing) |
| 122 | changed_items = zot.item_versions(since=1000) |
| 123 | ``` |
| 124 | |
| 125 | ## Library Settings |
| 126 | |
| 127 | ```python |
| 128 | settings = 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: |
| 132 | new_settings = zot.settings(since=500) |
| 133 | ``` |
| 134 | |
| 135 | ## Saved Searches |
| 136 | |
| 137 | ```python |
| 138 | searches = zot.searches() |
| 139 | # Retrieves saved search metadata (not results) |
| 140 | ``` |
| 141 | |
| 142 | ## Endpoint and Sync Boundaries |
| 143 | |
| 144 | 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`. |
| 145 | |
| 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. |
文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。

