====== Zotero Web API Documentation ====== The page documents read requests available in the [[start|Zotero Web API]], providing read-only access to online Zotero libraries. ===== Base URL ===== The base URL for all API requests is https://api.zotero.org All requests must use HTTPS. ===== API Versioning ===== Multiple versions of the API are available, and production code should always request a specific version. This page documents API version 3, which is currently the default and recommended version. Clients can request a specific version in one of two ways: - Via the ''Zotero-API-Version'' HTTP header (''Zotero-API-Version: 3'') - Via the ''v'' query parameter (''v=3'') Use of the ''Zotero-API-Version'' header is recommended for production code. The ''v'' parameter can be used for easier debugging and sharing of API requests or in clients that can't pass arbitrary HTTP headers. The API version of a response will be returned in the ''Zotero-API-Version'' response header. ==== Version Transitions ==== At most times, API changes are made in a backwards-compatible manner. Occasionally, however, backwards-incompatible changes may need to be made. When this occurs, a new API version will be made available without changing the default version for clients that don't request a specific version. After a transition period, the new API version will become the default. If an API version is discontinued, clients requesting the discontinued version will receive the oldest available version. Announcements regarding API version transitions will always be made ahead of time on [[https://groups.google.com/group/zotero-dev|zotero-dev]]. ===== Authentication ===== Authentication is not required for read access to public libraries. Accessing non-public libraries requires use of an API key. Third-party developers should [[oauth|use OAuth to establish credentials]] or instruct their users to create dedicated keys for use with their services. End users can create API keys via [[/settings/keys/new|their Zotero account settings]]. API keys can be included in requests in one of three ways: - As an HTTP header in the form ''Zotero-API-Key: P9NiFoyLeZu2bZNvvuQPDWsd'' \\ - As an HTTP header in the form ''Authorization: Bearer P9NiFoyLeZu2bZNvvuQPDWsd''\\ - As a URL query parameter, in the form ''key=P9NiFoyLeZu2bZNvvuQPDWsd'' (not recommended) Use of an HTTP header is recommended, as it allows use of URLs returned from the API (e.g., for pagination) without modification. ''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. ===== Resources ===== ==== User and Group Library URLs ==== Requests for data in a specific library begin with ''/users/'' or ''/groups/'', referred to below as ''''. User IDs are different from usernames and can be found on the [[/settings/keys|API Keys]] page and in OAuth responses. Group IDs are different from group names and can be retrieved from ''/users//groups''. === Collections === ^ URI ^ Description ^ | /collections | Collections in the library | | /collections/top | Top-level collections in the library | | /collections/ | A specific collection in the library | | /collections//collections | Subcollections within a specific collection in the library | === Items === ^ URI ^ Description ^ | /items | All items in the library, excluding trashed items | | /items/top | Top-level items in the library, excluding trashed items | | /items/trash | Items in the trash | | /items/ | A specific item in the library | | /items//children | Child items under a specific item | | /publications/items | Items in My Publications | | /collections//items | Items within a specific collection in the library | | /collections//items/top | Top-level items within a specific collection in the library | === Searches === (Note: Only search metadata is currently available, not search results.) ^ URI ^ Description ^ | /searches | All saved searches in the library | | /searches/ | A specific saved search in the library | === Tags === ^ URI ^ Description ^ | /tags | All tags in the library | | /tags/ | Tags of all types matching a specific name | | /items//tags | Tags associated with a specific item | | /collections//tags | Tags within a specific collection in the library | | /items/tags | All tags in the library, with the ability to filter based on the items | | /items/top/tags | Tags assigned to top-level items | | /items/trash/tags | Tags assigned to items in the trash | | /collections//items/tags | Tags assigned to items in a given collection | | /collections//items/top/tags | Tags assigned to top-level items in a given collection | | /publications/items/tags | Tags assigned to items in My Publications | ==== Other URLs ==== |< 100% 30% >| ^ URI ^ Description ^ | /keys/ | The user id and privileges of the given API key.\\ Use the ''DELETE'' HTTP method to delete the key. This should generally be done only by a client that created the key originally using [[OAuth]].| | /users//groups | The set of groups the current API key has access to, including public groups the key owner belongs to even if the key doesn't have explicit permissions for them. | ===== Read Requests ===== The following parameters affect the format of data returned from read requests. All parameters are optional. ==== General Parameters ==== The following parameters are valid for all read requests: ^ Parameter ^ Values ^ Default ^ Description ^ | ''format'' | ''atom'', ''bib'', ''json'', ''keys'', ''versions'', [[#export_formats|export format]] | ''json'' (or ''atom'' if the ''Accept'' header includes ''application/atom+xml'') | ''atom'' will return an Atom feed suitable for use in feed readers or feed-reading libraries.\\ ''bib'', valid only for item requests, will return a formatted bibliography as XHTML. ''bib'' mode is currently limited to a maximum of 150 items.\\ ''json'' will return a JSON array for multi-object requests and a single JSON object for single-object requests.\\ ''keys'', valid for multi-object requests, will return a newline-separated list of object keys. ''keys'' mode has no default or maximum limit.\\ ''versions'', valid for multi-object collection, item, and search requests, will return a JSON object with Zotero object keys as keys and object versions as values. Like ''keys'', ''versions'' mode has no default or maximum limit. \\ Export formats, valid only for item requests, produce output in the specified format. | ==== Parameters for "format=json" ==== ^ Parameter ^ Values ^ Default ^ Description ^ | ''include'' | ''bib'', ''citation'', ''data'', [[#export_formats|export format]]\\ Multiple formats can be specified by using a comma as the delimiter (''include=data,bib''). | ''data'' | Formats to include in the response:\\ ''bib'', valid only for item requests, will return a formatted reference for each item.\\ ''citation'', valid only for item requests, will return a formatted citation for each item.\\ ''data'' (the default) will include all writeable fields in JSON format, suitable for modifying and sending back to the API.\\ Export formats, valid only for item requests, will return data in the specified format for each item. | ==== Parameters for "format=atom" ==== ^ Parameter ^ Values ^ Default ^ Description ^ | ''content'' | ''bib'', ''citation'', ''html'', ''json'', [[#export_formats|export formats]], ''none''\\ Multiple formats can be specified by using a comma as the delimiter (''content=json,bib''). | ''html'' | The format of the Atom response's '''' node:\\ ''html'' (the default) will return an XHTML representation of each object, useful for display in feed readers and for parsing by XML tools.\\ ''json'', currently valid only for item and collection requests, will return a JSON representation of all the item's fields.\\ ''bib'', valid only for item requests, will return a formatted reference for each item.\\ ''citation'', valid only for item requests, will return a formatted citation for each item.\\ Export formats, valid only for item requests, will return data in the specified format for each item.\\ If additional data is not required, use ''none'' to decrease the response size.\\ If multiple formats are requested, '''' will contain multiple '''' elements (in the %%http://zotero.org/ns/api%% namespace), each with a ''zapi:type'' attribute matching one of the specified content parameters. | ==== Parameters for "format=bib", "include/content=bib", "include/content=citation" ==== ^ Parameter ^ Values ^ Default ^ Description ^ | ''style'' | string | ''chicago-note-bibliography'' | Citation style to use for formatted references. Can be either the file name (without the .csl extension) of one of the styles in the [[https://www.zotero.org/styles/|Zotero Style Repository]] (e.g., ''apa'') or the URL of a remote CSL file. | | ''linkwrap'' | boolean | ''0'' | Set to ''1'' to return URLs and DOIs as links | | ''locale'' | string | ''en-US'' | Bibliography locale. See the [[https://github.com/citation-style-language/locales|available CSL locales]]. Note that some styles use a fixed locale and cannot be localized. | Note the difference between ''format=bib'' and ''include=bib''/''content=bib''. ''format=bib'' returns a formatted bibliography as XHTML, sorted according to the rules of the selected style. ''include=bib'' (valid only for ''format=json'' (the default format mode) and ''format=atom'') returns an individual formatted reference within the JSON ''data'' block or Atom '''' block for each item, with the results or feed sorted according to the query parameters. ''format=bib'' processes the entire feed you are requesting without regard for any limit arguments, so it is generally a good idea to use it only with collections or tags. ==== Item Export Formats ==== The following bibliographic data formats can be used as ''format'', ''include'', and ''content'' parameters for items requests: ^ Parameter ^ Description ^ | ''bibtex'' | BibTeX | | ''biblatex''| BibLaTeX | | ''bookmarks'' | Netscape Bookmark File Format | | ''coins'' | COinS | | ''csljson'' | [[https://github.com/citation-style-language/schema/blob/master/csl-data.json|Citation Style Language data format]] | | ''csv'' | CSV | | ''mods'' | MODS | | ''refer'' | Refer/BibIX | | ''rdf_bibliontology'' | [[http://bibliontology.com/|Bibliographic Ontology]] RDF | | ''rdf_dc'' | Unqualified Dublin Core RDF | | ''rdf_zotero'' | Zotero RDF | | ''ris'' | RIS | | ''tei'' | Text Encoding Initiative (TEI) | | ''wikipedia'' | Wikipedia Citation Templates | ===== Searching ===== ==== Search Parameters ==== ^ Parameter ^ Values ^ Default ^ Description ^ | ''itemKey'' | string | null | A comma-separated list of item keys. Valid only for item requests. Up to 50 items can be specified in a single request. | | ''itemType'' | [[#search_syntax|search syntax]] | null | Item type search | | ''q'' | string | null | Quick search. Searches titles and individual creator fields by default. Use the ''qmode'' parameter to change the mode. Currently supports phrase searching only. | | ''since'' | integer | ''0'' | Return only objects modified after the specified library version, returned in a previous ''Last-Modified-Version'' header. See [[Syncing]] for more info. | | ''tag'' | [[#search_syntax|search syntax]] | null | Tag search | ==== Search Parameters (Items Endpoints) ==== ^ Parameter ^ Values ^ Default ^ Description ^ | ''includeTrashed'' | ''0'', ''1'' | ''0'' (except in ''/trash'') | Include items in the trash | | ''qmode'' | ''titleCreatorYear'', ''everything'' | ''titleCreatorYear'' | Quick search mode. To include full-text content, use ''everything''. Searching of other fields will be possible in the future. | ==== Search Parameters (Tags Endpoints) ==== ^ Parameter ^ Values ^ Default ^ Description ^ | ''qmode'' | ''contains'', ''startsWith'' | ''contains'' | Quick search mode. To perform a left-bound search, use ''startsWith''. | ==== Search Parameters (Tags-Within-Items Endpoints) ==== These parameters can be used to search against items when returning tags within items. In such cases, the main parameters (''q'', ''qmode'', ''tag'') apply to the tags themselves, as the primary objects of the request. ^ Parameter ^ Values ^ Default ^ Description ^ | ''itemQ'' | string | null | Same as ''q'' in an ''items'' request | | ''itemQMode'' | ''contains'', ''startsWith'' | ''contains'' | Same as ''qmode'' in an ''items'' request | | ''itemTag'' | [[#search_syntax|search syntax]] | null | Same as ''tag'' in an ''items'' request | ==== Search Syntax ==== ''itemType'' and ''tag'' parameters support Boolean searches: Examples: * ''itemType=book'' * ''itemType=book || journalArticle'' (OR) * ''itemType=-attachment'' (NOT) * ''tag=foo'' * ''tag=foo bar'' (tag with space) * ''tag=foo&tag=bar'' (AND) * ''tag=foo bar || bar'' (OR) * ''tag=-foo'' (NOT) * ''tag=\-foo'' (literal first-character hyphen) Be sure to URL-encode search strings if required by your client or library. ===== Sorting and Pagination ===== ==== Sorting and Pagination Parameters ==== The following parameters are valid only for multi-object read requests such as ''/items'', with the exception of ''format=bib'' requests, which do not support sorting or pagination. ^ Parameter ^ Values ^ Default ^ Description ^ | ''sort'' | ''dateAdded'', ''dateModified'', ''title'', ''creator'', ''itemType'', ''date'', ''publisher'', ''publicationTitle'', ''journalAbbreviation'', ''language'', ''accessDate'', ''libraryCatalog'', ''callNumber'', ''rights'', ''addedBy'', ''numItems'' (tags) | ''dateModified'' (''dateAdded'' for Atom) | The name of the field by which entries are sorted | | ''direction'' | ''asc'', ''desc'' | varies by ''sort'' | The sorting direction of the field specified in the ''sort'' parameter | | ''limit'' | integer 1-100* | ''25'' | The maximum number of results to return with a single request. Required for export formats. | | ''start'' | integer | ''0'' | The index of the first result. Combine with the limit parameter to select a slice of the available results. | === Total Results === 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. === Link Header === When the total number of results matched by a read request is greater than the current limit, the API will include pagination links in the HTTP ''Link'' header. Possible values are ''rel=first'', ''rel=prev'', ''rel=next'', and ''rel=last''. For some requests, the header may also include a ''rel=alternate'' link for the relevant page on the Zotero website. GET https://api.zotero.org/users/12345/items?limit=30 Link: ; rel="next", ; rel="last", ; rel="alternate" (Newlines are inserted here for clarity.) ===== Caching ===== For efficient usage of the API, clients should make conditional GET requests whenever possible. Multi-object requests (e.g., ''/users/1/items'') return a ''Last-Modified-Version'' header with the current library version. If a ''If-Modified-Since-Version: '' header is passed with a subsequent multi-object read request and data has not changed in the library since the specified version, the API will return ''304 Not Modified'' instead of ''200''. (Single-object conditional requests are not currently supported, but will be supported in the future.) While a conditional GET request that returns a ''304'' should be fast, some clients may wish or need to perform additional caching on their own, using stored data for a period of time before making subsequent conditional requests to the Zotero API. This makes particular sense when the underlying Zotero data is known not to change frequently or when the data will be accessed frequently. For example, a website that displayed a bibliography from a Zotero collection might cache the returned bibliography for an hour, after which time it would make another conditional request to the Zotero API. If the API returned a ''304'', the website would continue to display the cached bibliography for another hour before retrying. This would prevent the website from making a request to the Zotero API every time a user loaded a page. In addition to making conditional requests, clients downloading data for entire Zotero libraries should use ''?since='' to request only objects that have changed since the last time data was downloaded. See [[syncing|Syncing]] for more information on library and object versioning. ===== Rate Limiting ===== //[Not all rate limits are currently enforced, but clients should be prepared to handle them.]// Clients accessing the Zotero API should be prepared to handle two forms of rate limiting: backoff requests and hard limiting. If the API servers are overloaded, the API may include a ''Backoff: '' HTTP header in responses, indicating that the client should perform the minimum number of requests necessary to maintain data consistency and then refrain from making further requests for the number of seconds indicated. ''Backoff'' can be included in any response, including successful ones. If a client has made too many requests within a given time period or is making too many concurrent requests, the API may return ''429 Too Many Requests'' with a ''Retry-After: '' header. Clients receiving a ''429'' should wait at least the number of seconds indicated in the header before making further requests. They should also reduce their overall request rate and/or concurrency to avoid repeatedly getting 429s, which may result in stricter throttling or temporary blocks. ''Retry-After'' can also be included with ''503 Service Unavailable'' responses when the server is undergoing maintenance. ===== Example GET Requests and Responses ===== Several examples of read request URLs and their responses: ^ Multi-object JSON response: top-level items in a collection ^^ | Request | https://api.zotero.org/users/475425/collections/9KH9TNSJ/items/top?v=3 | | Response | https://gist.github.com/6eeace93a5c29775d39c | ^ Single-object JSON response: individual item ^^ | Request | https://api.zotero.org/users/475425/items/X42A7DEE?v=3 | | Response | https://gist.github.com/f1030b9609aadc51ddec | ^ Multi-object JSON response: collections for a user ^^ | Request | https://api.zotero.org/users/475425/collections?v=3 | | Response | https://gist.github.com/0bc17ca64ee7d3bc9063 | ^ Atom feed: items in a library ^^ | Request | https://api.zotero.org/users/475425/items?format=atom&v=3 | | Response |https://gist.github.com/24172188ea79efa210b5 | ^ Formatted bibliography: items in a collection^^ | Request | https://api.zotero.org/users/475425/collections/9KH9TNSJ/items?format=bib | | Response | https://gist.github.com/77bc2413cce4c219f862 | ===== HTTP Status Codes ===== Successful GET requests will return a ''200 OK'' status code. [[#caching|Conditional GET requests]] may return ''304 Not Modified''. For any read or write request, the server may return a ''400 Bad Request'', ''404 Not Found'', or ''405 Method Not Allowed'' for an invalid request and ''500 Internal Server Error'' or ''503 Service Unavailable'' for a server-related issue. [[#authentication|Authentication]] errors (e.g., invalid API key or insufficient privileges) will return a ''403 Forbidden''. Passing an ''Expect'' header, which is unsupported, will result in a ''417 Expectation Failed'' response. [[syncing#version_numbers|Library/object versioning]] or [[write_requests#zotero-write-token|Zotero-Write-Token]] errors will result in ''412 Precondition Failed'' or ''428 Precondition Required''. ''429 Too Many Requests'' indicates that the client has been [[#rate_limiting|rate-limited]]. ===== Additional API Documentation ===== * [[Write Requests]] * [[file_upload|File Uploads]] * [[Syncing]] * [[oauth|OAuth Authentication]] * [[changes_from_v2|Changes from API Version 2]]