Skip to content

Commit 04a91f8

Browse files
committed
Add local API documentation
1 parent 49df3b4 commit 04a91f8

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

content/dev/web_api/v3/basics.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Zotero Web API Documentation
22

3-
The page documents read requests available in the [Zotero Web API](dev/web_api/v3/), providing read-only access to online Zotero libraries.
3+
This page documents read requests available in the [Zotero Web API](dev/web_api/v3/), providing read-only access to online Zotero libraries. The Zotero desktop client exposes the same endpoints as a [local API](#local_api) that serves data from the local database, which is useful for code running on the user's computer.
44

55
## Base URL
66

77
The base URL for all API requests is
88

99
https://api.zotero.org
1010

11-
All requests must use HTTPS.
11+
All requests must use HTTPS. (The local API uses `http://localhost:23119/api/` instead; see [Local API](#local_api).)
1212

1313
## API Versioning
1414

@@ -43,6 +43,39 @@ Use of an HTTP header is recommended, as it allows use of URLs returned from the
4343

4444
`Authorization: Bearer` is also the authentication mechanism for OAuth 2.0. While Zotero currently supports only OAuth 1.0a, when support for OAuth 2.0 is added, clients will no longer need to extract the API key from the OAuth response and pass it to the API separately.
4545

46+
The [local API](#local_api) does not use authentication.
47+
48+
## Local API
49+
50+
Recent versions of the Zotero desktop client expose a local implementation of this API on `localhost:23119` under `/api/`, serving data from the user's local database. Because nothing touches the network, the local API works offline, has no rate limits, and is typically much faster than the Web API. It is intended for code running on the user's own computer, like utilities and command-line tools, that would otherwise need to read directly from the SQLite database or fall back to the Web API.
51+
52+
The local API must be enabled in Zotero's preferences (Settings → Advanced → "Allow other applications on this computer to communicate with Zotero"). Requests will return `403 Forbidden` if it is not enabled.
53+
54+
The base URL is
55+
56+
http://localhost:23119/api/
57+
58+
Most endpoints documented below work identically when accessed under that prefix. The notable differences from the Web API are:
59+
60+
- Only API version 3 is supported, and only one version will ever be supported at a time. If a future version is released and your client needs to work against both old and new copies of Zotero, request `/api/` first and read the `Zotero-API-Version` response header to determine which version the running client speaks before making further requests.
61+
- Write requests are currently unsupported. Only `GET` is accepted. (An upcoming version of Zotero will support write requests.)
62+
- There is no authentication. Anyone with access to the loopback interface can read the user's library, so do not forward the port or otherwise expose it externally.
63+
- Only data for the locally logged-in user is available. Pass `0` as the user ID or the user's actual numeric ID, which can be found on the [API Keys](/settings/keys) page. Requests for any other user ID return `400`.
64+
- Group metadata is limited to what's needed to identify the group; permissions, member lists, and similar details are not included.
65+
- Atom is not supported. Requests with `format=atom` or `content=atom` return `501 Not Implemented`.
66+
- Item type and field endpoints (see [Item Types and Fields](dev/web_api/v3/types_and_fields)) return localized names in the user's locale. The `locale` query parameter is ignored. `/api/creatorFields` is the exception and always returns English names, matching the Web API.
67+
- Results are not paginated by default. The local API will return the full set of matching objects in one response, since nothing has to be transferred over the network. The `limit` and `start` parameters still work if you want them, and `Link` headers are still included.
68+
- The implementation aims to match the Web API's documented behavior but does not attempt to replicate every implementation detail. Sort order on equal keys, quicksearch matching, and the exact JSON produced for an object may differ in minor ways. Clients that depend on undefined behavior or unusual corner cases of the Web API should be tested against both implementations.
69+
70+
The local API also supports a few things the Web API does not:
71+
72+
- `<userOrGroupPrefix>/searches/<searchKey>/items` returns the items matching a saved search. The Web API exposes search metadata but does not actually execute searches.
73+
- `<userOrGroupPrefix>/items/<itemKey>/file` returns a `302` redirect to a `file://` URL for the attachment on disk, and `/file/view` does the same. `/file/view/url` returns the URL as plain text rather than redirecting.
74+
75+
Responses include a `Zotero-Schema-Version` header reflecting the schema version of the local Zotero instance, which may lag behind or run ahead of the version served by the Web API.
76+
77+
The remainder of this page documents the API as a whole. Sections below note where local API behavior diverges from the Web API.
78+
4679
## Resources
4780

4881
### User and Group Library URLs
@@ -149,6 +182,8 @@ Export formats, valid only for item requests, produce output in the specified fo
149182
</tbody>
150183
</table>
151184

185+
The [local API](#local_api) does not support `format=atom`; requests using it return `501 Not Implemented`. All other formats are supported.
186+
152187
### Parameters for "format=json"
153188

154189
<table>
@@ -204,6 +239,8 @@ If multiple formats are requested, <code>&lt;content&gt;</code> will contain mul
204239
</tbody>
205240
</table>
206241

242+
The Atom parameters above do not apply to the [local API](#local_api), which does not produce Atom output.
243+
207244
### Parameters for "format=bib", "include/content=bib", "include/content=citation"
208245

209246
| Parameter | Values | Default | Description |
@@ -247,6 +284,8 @@ The following bibliographic data formats can be used as `format`, `include`, and
247284
| `since` | integer | `0` | Return only objects modified after the specified library version, returned in a previous `Last-Modified-Version` header. See [Syncing](dev/web_api/v3/syncing) for more info. |
248285
| `tag` | [search syntax](#search_syntax) | null | Tag search |
249286

287+
The [local API](#local_api) accepts the same search parameters but uses Zotero's local quicksearch implementation, so the set of items returned by a given `q` value may not match the Web API exactly.
288+
250289
### Search Parameters (Items Endpoints)
251290

252291
| Parameter | Values | Default | Description |
@@ -301,9 +340,11 @@ The following parameters are valid only for multi-object read requests such as `
301340
| `limit` | integer 1-100\* | `25` | The maximum number of results to return with a single request. Required for export formats. |
302341
| `start` | integer | `0` | The index of the first result. Combine with the limit parameter to select a slice of the available results. |
303342

343+
The [local API](#local_api) does not impose a default or maximum `limit`. If `limit` is omitted, all matching objects are returned in one response. Pagination parameters and `Link` headers still work for clients that want them.
344+
304345
#### Total Results
305346

306-
Responses for multi-object read requests will include a custom HTTP header, `Total-Results`, that provides the total number of results matched by the request. The actual number of results provided in a given response will be no more than 100.
347+
Responses for multi-object read requests will include a custom HTTP header, `Total-Results`, that provides the total number of results matched by the request. In the Web API, the actual number of results provided in a given response will be no more than 100.
307348

308349
#### Link Header
309350

@@ -327,6 +368,8 @@ In addition to making conditional requests, clients downloading data for entire
327368

328369
See [Syncing](dev/web_api/v3/syncing) for more information on library and object versioning.
329370

371+
Conditional requests work the same way against the [local API](#local_api), but local responses are already inexpensive to produce, so aggressive caching on the client side is less important. The `?since=` parameter is also supported and is the preferred way to fetch only changed objects from a large local library.
372+
330373
## Rate Limiting
331374

332375
Clients accessing the Zotero API should be prepared to handle two forms of rate limiting: backoff requests and hard limiting.
@@ -397,6 +440,8 @@ Several examples of read request URLs and their responses:
397440
</tbody>
398441
</table>
399442

443+
The [local API](#local_api) does not currently apply rate limiting.
444+
400445
## HTTP Status Codes
401446

402447
Successful GET requests will return a `200 OK` status code.
@@ -411,6 +456,8 @@ Passing an `Expect` header, which is unsupported, will result in a `417 Expectat
411456

412457
`429 Too Many Requests` indicates that the client has been [rate-limited](#rate_limiting).
413458

459+
The [local API](#local_api) returns `403 Forbidden` when the local API preference is not enabled and `501 Not Implemented` when a request asks for something it does not support (Atom output, or an API version other than 3 on an endpoint other than `/api/`).
460+
414461
## Additional API Documentation
415462

416463
- [Write Requests](dev/web_api/v3/write_requests)

0 commit comments

Comments
 (0)