| Title: | Zotero Integration Functions |
|---|---|
| Description: | Download complete Zotero group libraries via the Zotero Web API v3 in any of Zotero's export formats, and keep the local copies up to date by re-downloading only groups that changed on the server. |
| Authors: | Rainer Krug [aut, cre] |
| Maintainer: | Rainer Krug <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-16 10:48:48 UTC |
| Source: | https://github.com/rkrug/zotFunc |
This function retrieves data from a Zotero group using the Zotero API.
get_group( group_id = NULL, path = tempfile(), output_format = NULL, api_key = NULL, update = TRUE, force = FALSE, overwrite = FALSE, max_active = 4 )get_group( group_id = NULL, path = tempfile(), output_format = NULL, api_key = NULL, update = TRUE, force = FALSE, overwrite = FALSE, max_active = 4 )
group_id |
The ID of the Zotero group. If |
path |
The path to save the retrieved data. |
output_format |
The format of the output files. Supported are:
See the Zotero documentation
for details of the formats.
If not given, it is read from |
api_key |
API key for Zotero. Only needed for private groups. |
update |
If |
force |
If |
overwrite |
If |
max_active |
Number of pages (of 100 records) downloaded in parallel, from 1 to 4 (the maximum
number of concurrent requests Zotero asks for). Lower it if Zotero keeps answering with |
This function uses the Zotero API to retrieve data from a Zotero group. It downloads
the data in the format specified in output_format
and saves it in batches of 100 records to the folder specified by the path parameter.
Notes and attachments count as records for the API but are not exported in most formats, so pages
without any exported record (empty, or only the header for csv) are not saved.
NB: An existing path that is not a previous download (no .version) is only deleted and replaced
if overwrite = TRUE; otherwise an error is raised. An empty folder is used as is.
After the download, the group id and the library version at the start of the download are written to
the files .id and .version (and the group name in .name) in path. If path already contains such a download, group_outdated()
is used to check it: if the group differs from group_id, or the server version is older than the downloaded one,
an error is raised; if the versions are identical nothing is downloaded unless force = TRUE.
The output format is stored in .format (json for output_format = NULL). If output_format is not
given, it is read from there. If it is given and differs from .format, the group is downloaded again
in the new format, even if it is up to date.
The first page is downloaded alone, as it gives the number of records. The remaining pages are downloaded
in parallel, max_active at a time, following the
rate limits of the Zotero API:
no more than 4 concurrent requests, a Backoff header pauses the download for the given number of
seconds after the running requests, and a 429 or 503 response is retried after its Retry-After
(or with exponential backoff), pausing all other requests as well.
For further information about the allowed formats and other details on the API see https://www.zotero.org/support/dev/web_api/v3/start.
The path where the data is saved (also when nothing was downloaded).
# Download the Zotero group with ID 2352922 (IPBES IAS Assessment Bibliography) as JSON # into the folder "zotero_data" ## Not run: get_group(2352922, "zotero_data") # later: update it using only the folder get_group(path = "zotero_data") ## End(Not run)# Download the Zotero group with ID 2352922 (IPBES IAS Assessment Bibliography) as JSON # into the folder "zotero_data" ## Not run: get_group(2352922, "zotero_data") # later: update it using only the folder get_group(path = "zotero_data") ## End(Not run)
Queries the most recently modified item of a Zotero group and returns its modification time. Only items are considered (not collections or tags).
get_group_last_modified(group_id = 2352922, api_key = NULL)get_group_last_modified(group_id = 2352922, api_key = NULL)
group_id |
The ID of the Zotero group. |
api_key |
API key for Zotero. Only needed for private groups. |
The last modification time as a POSIXct (UTC), or NA if the group has no items.
## Not run: get_group_last_modified(2352922) ## End(Not run)## Not run: get_group_last_modified(2352922) ## End(Not run)
Returns the Last-Modified-Version of a Zotero group: an integer that increases
whenever anything in the group changes. Store it after a download and compare it
with the current value to decide whether a re-download is necessary.
get_group_version(group_id = 2352922, api_key = NULL)get_group_version(group_id = 2352922, api_key = NULL)
group_id |
The ID of the Zotero group. |
api_key |
API key for Zotero. Only needed for private groups. |
The library version as an integer.
## Not run: get_group_version(2352922) ## End(Not run)## Not run: get_group_version(2352922) ## End(Not run)
Lists the groups of a Zotero user.
get_groupids_from_user( zotero_user_name = "ipbes", zotero_user_id = NULL, api_key = NULL, verbose = FALSE )get_groupids_from_user( zotero_user_name = "ipbes", zotero_user_id = NULL, api_key = NULL, verbose = FALSE )
zotero_user_name |
Name of the user to download the groups from. If zotero_user_id is specified, not needed. Default: "ipbes". |
zotero_user_id |
Zotero user id to download the groups from. Default: obtained
through |
api_key |
Zotero API key, only needed for private groups. |
verbose |
logical. If TRUE, output is verbose |
NB: Only the first 25 groups are returned (the Zotero default page size).
Public groups work without an API key. For private groups, create a key with read access at Settings > Security (Create New Private Key, with Allow library access, Allow group access and Default Group Permissions: Read Only).
Character vector of group ids, named with the group names.
Downloads every group of a Zotero user with get_group(), each into the sub-folder
<group name>_<group id> of path. The update rules of get_group() apply to each group.
A group that fails prints its error and the next group continues.
get_groups_from_user( zotero_user_name = "ipbes", zotero_user_id = NULL, path = tempfile(), output_format = "rdf_zotero", api_key = Sys.getenv("ZOTERO_API_IPBES"), update = TRUE, force = FALSE, overwrite = FALSE, max_active = 4 )get_groups_from_user( zotero_user_name = "ipbes", zotero_user_id = NULL, path = tempfile(), output_format = "rdf_zotero", api_key = Sys.getenv("ZOTERO_API_IPBES"), update = TRUE, force = FALSE, overwrite = FALSE, max_active = 4 )
zotero_user_name |
Name of the user to download the groups from. Default: "ipbes".
If not given and |
zotero_user_id |
Zotero user id to download the groups from. Default: read from |
path |
Folder to save the groups in. |
output_format |
The output_format of the files. See |
api_key |
Zotero API key, only needed for private groups. Default: the environment variable |
update |
If |
force |
Passed to |
overwrite |
Passed to |
max_active |
Passed to |
The user id and name are stored in .user_id and .user_name in path, so later updates only need path.
Public groups work without an API key. For private groups, create a key with read access at Settings > Security (Create New Private Key, with Allow library access, Allow group access and Default Group Permissions: Read Only).
NULL, invisibly. Called for the downloads.
Compares the library version stored in group_dir/.version (written by get_group())
with the current version on the Zotero server.
group_outdated(group_dir, group_id = NULL, api_key = NULL)group_outdated(group_dir, group_id = NULL, api_key = NULL)
group_dir |
Folder of a previous |
group_id |
Optional. If given, it must match the group stored in |
api_key |
API key for Zotero. Only needed for private groups. |
A named logical, named with the group id: TRUE if the server version is
larger than the downloaded one, FALSE if they are identical.
An error is raised if the server version is smaller than the downloaded one,
if .id / .version are missing, or if group_id does not match .id.
## Not run: group_outdated("zotero_data") ## End(Not run)## Not run: group_outdated("zotero_data") ## End(Not run)
This function retrieves a Zotero user ID from a given username.
id_from_name(username)id_from_name(username)
username |
The Zotero username. Zotero Usernames are case sensitive! |
NB:The function relies on analysing the profile page. As this page might change, it is not recommended to use this function programmatically, but rather to retrieve the id and to use it hardcoded.
The Zotero user ID as a string.
## Not run: id_from_name("ipbes") # "5760254" ## End(Not run)## Not run: id_from_name("ipbes") # "5760254" ## End(Not run)