zotero-api-client
v0.51.0
Published
A lightweight, minimalistic Zotero API client
Readme
Zotero API client
A lightweight, minimalistic Zotero API client developed in JavaScript with the following goals:
- Small, single-purpose module: focuses solely on interacting with the API
- Compatible with both Node and browser environments
- No abstraction over Zotero data: what you see is what you get
- Clean API
- Small bundle footprint
- Minimal request validation
- Predictable and consistent responses
- Full test coverage
The client does not provide the following:
- Version management: version headers need to be provided explicitly
- Caching: each call to
get(),post(), etc., actually calls the API - Abstraction: there are no Item or Collection objects. The API response is returned with a minimal layer to automate common tasks and offers unrestricted access to the raw response JSON data.
Getting The Library
The NPM package includes the source of the library, which can be used as part of your build process (e.g., with Browserify, Rollup, Webpack, etc.) or directly in Node:
npm install zotero-api-clientThe package also includes a UMD bundle, which can be loaded with common module loaders or included directly in a <script> tag. In the latter case, the library will be available as a global object ZoteroApiClient. One way to use the UMD bundle on your page is to include it from the unpkg project CDN:
<script src="https://unpkg.com/zotero-api-client"></script>Example
A simple example of reading items from the public/test user library:
Import the library based on your environment:
// ES module, commonly used with a bundler: import api from 'zotero-api-client'; // CommonJS, for Node.js and some bundling cases: const { default: api } = require('zotero-api-client'); // UMD bundle creates `ZoteroApiClient` global object const { default: api } = ZoteroApiClient;Use the API to make the request (using async functions):
const response = await api().library('user', 475425).collections('9KH9TNSJ').items().get();Extract items from the response:
const items = response.getData();Print the titles of all items in the collection to the console:
console.log(items.map(i => i.title));
Overview
The library is composed of three layers:
apifunction: This is the only interface exported for use.- Request engine: This component does the heavy lifting and should not be used directly.
- ApiResponse class: A thin wrapper around the response. Multiple specialised variants exist for handling different response types.
API interface
The API interface is a function that returns a set of functions bound to previously configured options, allowing it to be chained and stored in a partially configured state. A common scenario is to store authentication and library details, which can be done as follows:
import api from 'zotero-api-client';
const myapi = api('AUTH_KEY').library('user', 0);This produces an API client already configured with your credentials and user library ID. You can now use myapi to obtain the list of collections in that library:
const collectionsResponse = await myapi.collections().get();Items in that library:
const itemsResponse = await myapi.items().get();Or items in a specific collection:
const collectionItemsResponse = await myapi.collections('EXAMPLE1').items().get();There are two types of API functions:
- Configuration functions (e.g.,
items()) that can be further chained. - Execution functions (e.g.,
get()) that trigger the request.
For a complete reference, see the documentation for api().
Response
The response is an instance of a specialised response class object returned by one of the execution functions of the api. Each response includes a specialised getData() method, which returns the entities that were requested or modified, depending on the request configuration.
For a complete reference, see the documentation for SingleReadResponse, MultiReadResponse, SingleWriteResponse, MultiWriteResponse, DeleteResponse, FileUploadResponse, FileDownloadResponse, FileUrlResponse.
Request
The request function takes a configuration object generated by the API interface, communicates with the API, and returns one of the response objects (see above). Some rarely used properties cannot be configured through API configuration functions and must be specified as optional properties when calling api() or one of the API's execution functions.
For a complete list of all properties request() accepts, please refer to the documentation for request().
Local API
The Zotero desktop application can serve a local version of the API at http://localhost:23119/api/ (enable "Allow other applications on this computer to communicate with Zotero" in Zotero's Advanced settings). It mirrors the web API, user ID 0 refers to the local profile's user. Read requests require no API key:
const localapi = api('', { apiScheme: 'http', apiAuthorityPart: 'localhost:23119', apiPath: 'api/' });
const response = await localapi.library('user', 0).items().get();Write requests require two extra pieces:
- Server ID: every write must carry a
Zotero-Server-IDheader identifying the Zotero instance. Every local API response includes this header, so it can be bootstrapped with a bare root request. - Local API key: requested with
local().authorize(), which makes Zotero prompt the user to allow write access for your app.
const serverID = (await localapi.get()).getServerID();
const auth = await localapi.serverID(serverID).local().authorize('My App').post();
const key = auth.getKey();If the user picks "Always allow", auth.isRemembered() returns true and the key remains valid until revoked in Zotero's settings. Otherwise the key is single-use: it is consumed by the first write request, and a write with a used or unknown key fails with 401, at which point authorization should be requested again.
With both in hand, writes look exactly like web API writes:
await api(key, { apiScheme: 'http', apiAuthorityPart: 'localhost:23119', apiPath: 'api/' })
.library('user', 0).serverID(serverID).items().post([ /* items */ ]);Note: the local API drops requests that appear to come from a browser (a Mozilla/ user agent or an Origin header) unless the Zotero-Allowed-Request header is present; set it via the zoteroAllowedRequest option.
API Reference
- zotero-api-client
- ~ApiResponse
- .getResponseType() ⇒ string
- .getData() ⇒ object
- .getLinks() ⇒ object
- .getMeta() ⇒ object
- .getVersion() ⇒ number
- .getServerID() ⇒ string
- ~FullTextStatusResponse ⇐ ApiResponse
- .getResponseType()
- .getStatus() ⇒ string
- .getIndexedCount() ⇒ number
- .getExpectedCount() ⇒ number
- ~SingleReadResponse ⇐ ApiResponse
- .getResponseType()
- .getData() ⇒ Object
- ~MultiReadResponse ⇐ ApiResponse
- .getResponseType()
- .getData() ⇒ Array
- .getLinks() ⇒ Array
- .getMeta() ⇒ Array
- .getTotalResults() ⇒ number
- .getRelLinks() ⇒ object
- ~SingleWriteResponse ⇐ ApiResponse
- .getResponseType()
- .getData() ⇒ Object
- ~MultiWriteResponse ⇐ ApiResponse
- .getResponseType()
- .isSuccess() ⇒ Boolean
- .getData() ⇒ Array
- .getLinks()
- .getMeta()
- .getErrors() ⇒ Object
- .getEntityByKey(key) ⇒ Object
- .getEntityByIndex(index) ⇒ Object
- ~DeleteResponse ⇐ ApiResponse
- ~AuthorizeResponse ⇐ ApiResponse
- .getResponseType()
- .getKey() ⇒ string
- .isRemembered() ⇒ boolean
- ~FileUploadResponse ⇐ ApiResponse
- ~FileDownloadResponse ⇐ ApiResponse
- ~FileUrlResponse ⇐ ApiResponse
- ~RawApiResponse ⇐ ApiResponse
- ~PretendResponse ⇐ ApiResponse
- .getResponseType()
- .getVersion() ⇒ Object
- ~ErrorResponse ⇐ Error
- .getVersion() ⇒ number
- .getServerID() ⇒ string
- .getResponseType()
- ~api() ⇒ Object
- ~api(key, opts) ⇒ Object
- ~library([typeOrKey], [id]) ⇒ Object
- ~items(items) ⇒ Object
- ~itemTypes() ⇒ Object
- ~itemFields() ⇒ Object
- ~creatorFields() ⇒ Object
- ~schema() ⇒ Object
- ~fulltextStatus() ⇒ Object
- ~fulltext() ⇒ Object
- ~itemTypeFields(itemType) ⇒ Object
- ~itemTypeCreatorTypes(itemType) ⇒ Object
- ~template(itemType, subType) ⇒ Object
- ~collections(collections) ⇒ Object
- ~subcollections() ⇒ Object
- ~publications() ⇒ Object
- ~tags(tags) ⇒ Object
- ~searches(searches) ⇒ Object
- ~top() ⇒ Object
- ~trash() ⇒ Object
- ~children() ⇒ Object
- ~settings(settings) ⇒ Object
- ~deleted(since) ⇒ Object
- ~groups() ⇒ Object
- ~version(version) ⇒ Object
- ~apiVersion(apiVersion) ⇒ Object
- ~serverID(serverID) ⇒ Object
- ~attachment([fileName], [file], [mtime], [md5sum], [patch], [algorithm], [zipFilename]) ⇒ Object
- ~registerAttachment(fileName, fileSize, mtime, md5sum, [zipMD5], [zipFilename]) ⇒ Object
- ~attachmentUrl() ⇒ Object
- ~verifyKeyAccess() ⇒ Object
- ~local() ⇒ Object
- ~authorize(appName) ⇒ Object
- ~get(opts) ⇒ Promise
- ~post(data, opts) ⇒ Promise
- ~put(data, opts) ⇒ Promise
- ~patch(data, opts) ⇒ Promise
- ~del(keysToDelete, opts) ⇒ Promise
- ~getConfig() ⇒ Object
- ~pretend(verb, data, opts) ⇒ Promise
- ~use(extend) ⇒ Object
- ~request(config) ⇒ Promise
- ~ApiResponse
zotero-api-client~ApiResponse
Represents a generic Zotero API response. Usually a specialised variant inheriting from this class is returned when doing an API request
Kind: inner class of zotero-api-client
- ~ApiResponse
- .getResponseType() ⇒ string
- .getData() ⇒ object
- .getLinks() ⇒ object
- .getMeta() ⇒ object
- .getVersion() ⇒ number
- .getServerID() ⇒ string
apiResponse.getResponseType() ⇒ string
Name of the class, useful to determine instance of which specialised class has been returned
Kind: instance method of ApiResponse
Returns: string - name of the class
apiResponse.getData() ⇒ object
Content of the response. Specialised classes provide extracted data depending on context.
Kind: instance method of ApiResponse
apiResponse.getLinks() ⇒ object
Links available in the response. Specialised classes provide extracted links depending on context.
Kind: instance method of ApiResponse
apiResponse.getMeta() ⇒ object
Meta data available in the response. Specialised classes provide extracted meta data depending on context.
Kind: instance method of ApiResponse
apiResponse.getVersion() ⇒ number
Value of the "Last-Modified-Version" header in response if present. Specialised classes provide version depending on context
Kind: instance method of ApiResponse
Returns: number - Version of the content in response
apiResponse.getServerID() ⇒ string
Value of the "Zotero-Server-ID" header in response if present. Identifies the Zotero instance that served the request when using the local API
Kind: instance method of ApiResponse
Returns: string - ID of the Zotero instance that produced the response
zotero-api-client~FullTextStatusResponse ⇐ ApiResponse
Represents a response to a GET request for a library's full-text index status
Kind: inner class of zotero-api-client
Extends: ApiResponse
- ~FullTextStatusResponse ⇐ ApiResponse
- .getResponseType()
- .getStatus() ⇒ string
- .getIndexedCount() ⇒ number
- .getExpectedCount() ⇒ number
fullTextStatusResponse.getResponseType()
Kind: instance method of FullTextStatusResponse
See: getResponseType
fullTextStatusResponse.getStatus() ⇒ string
Kind: instance method of FullTextStatusResponse
Returns: string - Index status, one of "indexed", "incomplete", "reindexing" or "deindexed"
fullTextStatusResponse.getIndexedCount() ⇒ number
Kind: instance method of FullTextStatusResponse
Returns: number - Number of items currently indexed, or null when not reported (status "indexed"/"deindexed")
fullTextStatusResponse.getExpectedCount() ⇒ number
Kind: instance method of FullTextStatusResponse
Returns: number - Number of items expected to be indexed, or null when not reported (status "indexed"/"deindexed")
zotero-api-client~SingleReadResponse ⇐ ApiResponse
Represents a response to a GET request containing a single entity
Kind: inner class of zotero-api-client
Extends: ApiResponse
- ~SingleReadResponse ⇐ ApiResponse
- .getResponseType()
- .getData() ⇒ Object
singleReadResponse.getResponseType()
Kind: instance method of SingleReadResponse
See: getResponseType
singleReadResponse.getData() ⇒ Object
Kind: instance method of SingleReadResponse
Returns: Object - entity returned in this response
zotero-api-client~MultiReadResponse ⇐ ApiResponse
represents a response to a GET request containing multiple entities
Kind: inner class of zotero-api-client
Extends: ApiResponse
- ~MultiReadResponse ⇐ ApiResponse
- .getResponseType()
- .getData() ⇒ Array
- .getLinks() ⇒ Array
- .getMeta() ⇒ Array
- .getTotalResults() ⇒ number
- .getRelLinks() ⇒ object
multiReadResponse.getResponseType()
Kind: instance method of MultiReadResponse
See: getResponseType
multiReadResponse.getData() ⇒ Array
Kind: instance method of MultiReadResponse
Returns: Array - a list of entities returned in this response
multiReadResponse.getLinks() ⇒ Array
Kind: instance method of MultiReadResponse
Returns: Array - a list of links, indexes of the array match indexes of entities in getData
multiReadResponse.getMeta() ⇒ Array
Kind: instance method of MultiReadResponse
Returns: Array - a list of meta-data, indexes of the array match indexes of entities in getData
multiReadResponse.getTotalResults() ⇒ number
Kind: instance method of MultiReadResponse
Returns: number - Total number of results
multiReadResponse.getRelLinks() ⇒ object
Kind: instance method of MultiReadResponse
Returns: object - Parsed content of "Link" header as an object where value of "rel" is a key and
the URL is the value. For paginated responses contain URLs for "first", "next", "prev" and "last".
zotero-api-client~SingleWriteResponse ⇐ ApiResponse
Represents a response to a PUT or PATCH request
Kind: inner class of zotero-api-client
Extends: ApiResponse
- ~SingleWriteResponse ⇐ ApiResponse
- .getResponseType()
- .getData() ⇒ Object
singleWriteResponse.getResponseType()
Kind: instance method of SingleWriteResponse
See: getResponseType
singleWriteResponse.getData() ⇒ Object
Kind: instance method of SingleWriteResponse
Returns: Object - For put requests, this represents a complete, updated object.
For patch requests, this represents only updated fields of the updated object.
zotero-api-client~MultiWriteResponse ⇐ ApiResponse
Represents a response to a POST request
Kind: inner class of zotero-api-client
Extends: ApiResponse
- ~MultiWriteResponse ⇐ ApiResponse
- .getResponseType()
- .isSuccess() ⇒ Boolean
- .getData() ⇒ Array
- .getLinks()
- .getMeta()
- .getErrors() ⇒ Object
- .getEntityByKey(key) ⇒ Object
- .getEntityByIndex(index) ⇒ Object
multiWriteResponse.getResponseType()
Kind: instance method of MultiWriteResponse
See: getResponseType
multiWriteResponse.isSuccess() ⇒ Boolean
Kind: instance method of MultiWriteResponse
Returns: Boolean - Indicates whether all write operations were successful
multiWriteResponse.getData() ⇒ Array
Returns all entities POSTed in an array. Entities that have been written successfully are returned updated, other entities are returned unchanged. It is advised to verify if the request was entirely successful (see isSuccess and getErrors) before using this method.
Kind: instance method of MultiWriteResponse
Returns: Array - A modified list of all entities posted.
multiWriteResponse.getLinks()
Kind: instance method of MultiWriteResponse
See: getLinks
multiWriteResponse.getMeta()
Kind: instance method of MultiWriteResponse
See: getMeta
multiWriteResponse.getErrors() ⇒ Object
Returns all errors that have occurred.
Kind: instance method of MultiWriteResponse
Returns: Object - Errors object where keys are indexes of the array of the original request and values are the errors occurred.
multiWriteResponse.getEntityByKey(key) ⇒ Object
Allows getting an updated entity based on its key, otherwise identical to getEntityByIndex
Kind: instance method of MultiWriteResponse
Throws:
- Error If key is not present in the request
See: getEntityByIndex
| Param | Type | | --- | --- | | key | String |
multiWriteResponse.getEntityByIndex(index) ⇒ Object
Allows getting an updated entity based on its index in the original request
Kind: instance method of MultiWriteResponse
Throws:
- Error If index is not present in the original request
- Error If error occurred in the POST for selected entity. Error message will contain the reason for failure.
| Param | Type | | --- | --- | | index | Number | String |
zotero-api-client~DeleteResponse ⇐ ApiResponse
Represents a response to a DELETE request
Kind: inner class of zotero-api-client
Extends: ApiResponse
deleteResponse.getResponseType()
Kind: instance method of DeleteResponse
See: getResponseType
zotero-api-client~AuthorizeResponse ⇐ ApiResponse
Represents a response to a local API authorization request (POST /api/local/authorize). Local API only
Kind: inner class of zotero-api-client
Extends: ApiResponse
- ~AuthorizeResponse ⇐ ApiResponse
- .getResponseType()
- .getKey() ⇒ string
- .isRemembered() ⇒ boolean
authorizeResponse.getResponseType()
Kind: instance method of AuthorizeResponse
See: getResponseType
authorizeResponse.getKey() ⇒ string
Local API key granted by the user, to be sent in the "Zotero-API-Key" header on subsequent write requests
Kind: instance method of AuthorizeResponse
Returns: string - Local API key authorizing write requests
authorizeResponse.isRemembered() ⇒ boolean
Whether the user granted persistent access ("Always Allow"). When false, the key is single-use: the first write request that successfully validates it consumes it
Kind: instance method of AuthorizeResponse
Returns: boolean - Whether the key is persistent
zotero-api-client~FileUploadResponse ⇐ ApiResponse
Represents a response to a file upload request
Kind: inner class of zotero-api-client
Extends: ApiResponse
Properties
| Name | Type | Description | | --- | --- | --- | | authResponse | Object | Response object for stage 1 (upload authorisation) request | | response | Object | alias for "authResponse" | | uploadResponse | Object | Response object for stage 2 (file upload) request | | registerResponse | Object | Response object for stage 3 (upload registration) request |
- ~FileUploadResponse ⇐ ApiResponse
fileUploadResponse.getResponseType()
Kind: instance method of FileUploadResponse
See: getResponseType
fileUploadResponse.getVersion()
Kind: instance method of FileUploadResponse
See: getVersion
zotero-api-client~FileDownloadResponse ⇐ ApiResponse
Represents a response to a file download request
Kind: inner class of zotero-api-client
Extends: ApiResponse
fileDownloadResponse.getResponseType()
Kind: instance method of FileDownloadResponse
See: getResponseType
zotero-api-client~FileUrlResponse ⇐ ApiResponse
Represents a response containing temporary url for file download
Kind: inner class of zotero-api-client
Extends: ApiResponse
fileUrlResponse.getResponseType()
Kind: instance method of FileUrlResponse
See: getResponseType
zotero-api-client~RawApiResponse ⇐ ApiResponse
Represents a raw response, e.g. to data requests with format other than JSON
Kind: inner class of zotero-api-client
Extends: ApiResponse
rawApiResponse.getResponseType()
Kind: instance method of RawApiResponse
See: getResponseType
zotero-api-client~PretendResponse ⇐ ApiResponse
Represents a response for pretended request, mostly for debug purposes. See module:zotero-api-client.api~pretend
Kind: inner class of zotero-api-client
Extends: ApiResponse
- ~PretendResponse ⇐ ApiResponse
- .getResponseType()
- .getVersion() ⇒ Object
pretendResponse.getResponseType()
Kind: instance method of PretendResponse
See: getResponseType
pretendResponse.getVersion() ⇒ Object
Kind: instance method of PretendResponse
Returns: Object - For pretended request version will always be null.
zotero-api-client~ErrorResponse ⇐ Error
Represents an error response from the api
Kind: inner class of zotero-api-client
Extends: Error
Properties
| Name | Type | Description | | --- | --- | --- | | response | Object | Response object for the request, with untouched body | | message | String | What error occurred, usually contains response code and status | | reason | String | More detailed reason for the failure, if provided by the API | | options | Object | Configuration object used for this request |
- ~ErrorResponse ⇐ Error
- .getVersion() ⇒ number
- .getServerID() ⇒ string
- .getResponseType()
errorResponse.getVersion() ⇒ number
Value of the "Last-Modified-Version" header in response if present. This is generally only available if the server responded with 412 due to a version mismatch.
Kind: instance method of ErrorResponse
Returns: number - Version of the content in response
errorResponse.getServerID() ⇒ string
Value of the "Zotero-Server-ID" header in response if present. Identifies the Zotero instance that served the request when using the local API
Kind: instance method of ErrorResponse
Returns: string - ID of the Zotero instance that produced the response
errorResponse.getResponseType()
Kind: instance method of ErrorResponse
See: getResponseType
zotero-api-client~api() ⇒ Object
Wrapper function creates closure scope and calls api()
Kind: inner method of zotero-api-client
Returns: Object - Partially configured api functions
- ~api() ⇒ Object
- ~api(key, opts) ⇒ Object
- ~library([typeOrKey], [id]) ⇒ Object
- ~items(items) ⇒ Object
- ~itemTypes() ⇒ Object
- ~itemFields() ⇒ Object
- ~creatorFields() ⇒ Object
- ~schema() ⇒ Object
- ~fulltextStatus() ⇒ Object
- ~fulltext() ⇒ Object
- ~itemTypeFields(itemType) ⇒ Object
- ~itemTypeCreatorTypes(itemType) ⇒ Object
- ~template(itemType, subType) ⇒ Object
- ~collections(collections) ⇒ Object
- ~subcollections() ⇒ Object
- ~publications() ⇒ Object
- ~tags(tags) ⇒ Object
- ~searches(searches) ⇒ Object
- ~top() ⇒ Object
- ~trash() ⇒ Object
- ~children() ⇒ Object
- ~settings(settings) ⇒ Object
- ~deleted(since) ⇒ Object
- ~groups() ⇒ Object
- ~version(version) ⇒ Object
- ~apiVersion(apiVersion) ⇒ Object
- ~serverID(serverID) ⇒ Object
- ~attachment([fileName], [file], [mtime], [md5sum], [patch], [algorithm], [zipFilename]) ⇒ Object
- ~registerAttachment(fileName, fileSize, mtime, md5sum, [zipMD5], [zipFilename]) ⇒ Object
- ~attachmentUrl() ⇒ Object
- ~verifyKeyAccess() ⇒ Object
- ~local() ⇒ Object
- ~authorize(appName) ⇒ Object
- ~get(opts) ⇒ Promise
- ~post(data, opts) ⇒ Promise
- ~put(data, opts) ⇒ Promise
- ~patch(data, opts) ⇒ Promise
- ~del(keysToDelete, opts) ⇒ Promise
- ~getConfig() ⇒ Object
- ~pretend(verb, data, opts) ⇒ Promise
- ~use(extend) ⇒ Object
api~api(key, opts) ⇒ Object
Entry point of the interface. Configures authentication. Can be used to configure any other properties of the api Returns a set of functions that are bound to that configuration and can be called to specify further api configuration.
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | key | String | Authentication key | | opts | Object | Optional api configuration. For a list of all possible properties, see documentation for request() function | | opts.skipValidation | Boolean | skip client-side validation of the resource/method combination. Validation is a chain-layer feature only; calling request() directly is never validated. |
api~library([typeOrKey], [id]) ⇒ Object
Configures which library api requests should use.
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Default | Description | | --- | --- | --- | --- | | [typeOrKey] | * | | Library key, e.g. g1234. Alternatively, if the second parameter is present, library type i.e. either 'group' or 'user' | | [id] | Number | | Only when first argument is a type, library id |
api~items(items) ⇒ Object
Configures api to use items or a specific item Can be used in conjunction with library(), collections(), top(), trash(), children(), tags() and any execution function (e.g. get(), post())
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Default | Description | | --- | --- | --- | --- | | items | String | | Item key, if present, configure api to point at this specific item |
api~itemTypes() ⇒ Object
Configure api to request all item types Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~itemFields() ⇒ Object
Configure api to request all item fields Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~creatorFields() ⇒ Object
Configure api to request localized creator fields Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~schema() ⇒ Object
Configure api to request schema Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~fulltextStatus() ⇒ Object
Configure api to request the full-text index status for a library Must be used in conjunction with library() and get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~fulltext() ⇒ Object
Configure api to request or write full-text content.
When used in conjunction with library() and items() with a single item key,
use get() to retrieve and put() to store full-text content for that
attachment item.
When used in conjunction with library() alone, use get() with a since
option to request a map of item keys to full-text content versions, or
post() to write full-text content for multiple items at a time.
The library-scoped endpoint only accepts format: 'versions'.
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~itemTypeFields(itemType) ⇒ Object
Configure api to request all valid fields for an item type Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | itemType | String | item type for which valid fields will be requested, e.g. 'book' or 'journalType' |
api~itemTypeCreatorTypes(itemType) ⇒ Object
Configure api to request valid creator types for an item type Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | itemType | String | item type for which valid creator types will be requested, e.g. 'book' or 'journalType' |
api~template(itemType, subType) ⇒ Object
Configure api to request template for a new item Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | itemType | String | item type for which template will be requested, e.g. 'book' or 'journalType' | | subType | String | annotationType if itemType is 'annotation' or linkMode if itemType is 'attachment' |
api~collections(collections) ⇒ Object
Configure api to use collections or a specific collection Can be used in conjunction with library(), items(), top(), tags() and any of the execution function (e.g. get(), post())
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | collections | String | Collection key, if present, configure api to point to this specific collection |
api~subcollections() ⇒ Object
Configure api to use subcollections that reside underneath the specified collection. Should only be used in conjunction with both library() and collections() and any of the execution function (e.g. get(), post())
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~publications() ⇒ Object
Configure api to narrow the request to only consider items filed under "My Publications" Should only be used in conjunction with both library() and items() and any of the execution function (e.g. get(), post())
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~tags(tags) ⇒ Object
Configure api to request or delete tags or request a specific tag Can be used in conjunction with library(), items(), collections() and any of the following execution functions: get(), delete() but only if the first argument is not present. Otherwise, can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Default | Description | | --- | --- | --- | --- | | tags | String | | name of a tag to request. If present, configure api to request a specific tag. |
api~searches(searches) ⇒ Object
Configure api to use saved searches or a specific saved search Can be used in conjunction with library() and any of the execution functions
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Default | Description | | --- | --- | --- | --- | | searches | String | | Search key, if present, configure api to point at this specific saved search |
api~top() ⇒ Object
Configure api to narrow the request only to the top level items Can be used in conjunction with items() and collections() and only with conjunction with a get() execution function
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~trash() ⇒ Object
Configure api to narrow the request only to the items in the trash Can be only used in conjunction with items() and get() execution function
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~children() ⇒ Object
Configure api to narrow the request only to the children of given item Can be only used in conjunction with items() and get() execution function
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~settings(settings) ⇒ Object
Configure api to request settings Can only be used in conjunction with get(), put(), post() and delete() For usage with put() and delete() a settings key must be provided For usage with post() a settings key must not be included
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| settings | String | | Settings "key", if present, configures api to point at this specific key within settings, e.g. tagColors. |
api~deleted(since) ⇒ Object
Configure api to request deleted content Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | since | Number | library version to request deletions since |
api~groups() ⇒ Object
Configure api to request user-accessible groups (i.e. 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.) Can only be used in conjunction with get()
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
api~version(version) ⇒ Object
Configure api to specify a local version of a given entity. When used in conjunction with the get() exec function, it will populate the If-Modified-Since-Version header. When used in conjunction with post(), put(), patch() or delete(), it will populate the If-Unmodified-Since-Version header.
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | version | Number | local version of the entity |
api~apiVersion(apiVersion) ⇒ Object
Configure api to request a specific version of the Zotero API, populating the Zotero-API-Version header. This is optional: the API defaults to version 3 when no version is requested. Pinning a version insulates a client against a future, backwards-incompatible API version becoming the default.
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | apiVersion | Number | Zotero API version to request, e.g. 3 |
api~serverID(serverID) ⇒ Object
Configure api to send the "Zotero-Server-ID" header with the request. Only used with the local API: every local API response identifies the Zotero instance that produced it in a "Zotero-Server-ID" header (see getServerID) and write requests must echo that value back to confirm they're reaching the same instance.
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description | | --- | --- | --- | | serverID | String | Server ID previously obtained from a local API response |
api~attachment([fileName], [file], [mtime], [md5sum], [patch], [algorithm], [zipFilename]) ⇒ Object
Configure api to upload or download an attachment file.
Can be only used in conjunction with items() and post()/get()/patch().
Method patch() can only be used to upload a binary patch, in this case the last two arguments
must be provided.
Method post() is used for full uploads. If md5sum is provided, it will update an existing
file, otherwise it uploads a new file. The last two arguments are not used in this scenario.
Method get() is used for downloads, in this case skip all arguments.
Use items() to select the attachment item for which the file is uploaded/downloaded.
Will populate format on download as well as Content-Type, If*Match headers in case of upload.
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description |
| --- | --- | --- |
| [fileName] | String | For upload: name of the file, should match values in attachment item entry |
| [file] | ArrayBuffer | New file to be uploaded |
| [mtime] | Number | New file's mtime, leave empty to assume current date/time |
| [md5sum] | String | MD5 hash of an existing file, required for uploads that update existing file |
| [patch] | ArrayBuffer | Binary patch, to be applied to the old file, to produce a new file |
| [algorithm] | String | Algorithm used to compute a diff: xdelta, vcdiff or bsdiff |
| [zipFilename] | String | Filename of the zip wrapper on S3 (typically <itemKey>.zip) for zip-stored attachments (e.g. HTML snapshots). When provided, file is interpreted as the wrapper bytes; the wrapper MD5 is computed and sent as zipMD5, while the existing md5sum value populates the body's inner md5 field (preserving attachmentStorageHash). Requires md5sum; incompatible with patch/algorithm. |
api~registerAttachment(fileName, fileSize, mtime, md5sum, [zipMD5], [zipFilename]) ⇒ Object
Advanced function that will attempt to register an existing file with a given attachment item based on known file metadata. Can also be used to rename an existing file. Can be only used in conjunction with items() and post(). Use items() to select the attachment item for which a file is registered. Will populate Content-Type, If-Match headers. Will fail with a ErrorResponse if API does not return "exists".
Kind: inner method of api
Chainable
Returns: Object - Partially configured api functions
| Param | Type | Description |
| --- | --- | --- |
| fileName | String | name of the file, should match value in the item, unless renaming |
| fileSize | Number | size of the existing file |
| mtime | Number | mtime of the existing file |
| md5sum | String | md5sum of the existing file |
| [zipMD5] | String | MD5 hash of the existing zip wrapper on S3 (for zip-stored attachments such as HTML snapshots). Required together with zipFilename when re-registering a zip-stored attach
