This is the one-time setup. It takes about five minutes, and you do not need to repeat it for each project. You need to:
None of the code in this vignette is run when the vignette is built, because it needs your Zotero account.
citezot talks to the Zotero web API, so it needs an API key. Zotero desktop does not have to be running, but your library must be synced to zotero.org (in Zotero desktop: Settings, Sync).
citezot-key.A read-only key is enough for cz_update_bib(),
cz_find(), cz_get_item() and
cz_fetch_items(). Only the functions that change your
library (cz_add(), cz_update_item() and
cz_pin_key()) need Allow write access.
Those functions are dry runs unless you pass
dry_run = FALSE, and citezot has no delete, but a read-only
key is technically the safer choice, because it cannot change your
library no matter what. You can edit the key on the same page later to
add write access.
For a group library, create the key under Group permissions
on the same page. The group ID is the number in the group’s URL
(https://www.zotero.org/groups/<ID>/<name>).
Then set ZOTERO_LIBRARY_ID (below) to that group ID and use
cz_auth(library_type = "group").
citezot reads these environment variables:
| Variable | What it holds |
|---|---|
ZOTERO_API_KEY |
the API key |
ZOTERO_LIBRARY_ID |
the numeric ID of your personal library (your user ID), or of a group library |
Save them to your user-level .Renviron,
so they are available in every project and cannot be committed by
accident. cz_set_auth() does this for you. It asks for the
ID and key (so they never land in your command history), writes the
file, and makes them available in the current session straight away:
Prefer to edit the file yourself? Run
usethis::edit_r_environ(), add the two lines below, save,
and restart R (.Renviron is read only at
startup):
ZOTERO_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxx
ZOTERO_LIBRARY_ID=1234567
Either way, check that citezot can see the credentials. The key is never printed:
Do not put the key in a file inside a project. If you must, make sure
the file is in .gitignore.
api.zotero.org, as a bearer
token.print() on an auth
object hides it.cz_clear_cache()) holds
bibliographic metadata, never the key.citezot cites an item by the citekey saved on it. An
item without one cannot be cited, and cz_update_bib() will
tell you which keys it could not find.
There are two ways to get a key onto an item.
Better BibTeX generates keys from a formula you choose, and can pin them so they never change. Pinned keys are saved on the item, which is what citezot reads. In Zotero desktop, select the items, right-click, then Better BibTeX and Pin BibTeX key. Syncing then uploads the keys.
Better BibTeX is optional. citezot does not need it to read keys.
Zotero stores the key in each item’s Citation Key field. You can set it by hand in Zotero, or from R:
cz_find("darwin origin of species") # find the item
cz_pin_key("Darwin1859", "Darwin1859") # preview; item = any of the identifiers cz_find() understands
cz_add("10.1016/0022-5193(64)90038-4", key = "auto") # or add a new item with a generated keySee vignette("manuscript") for the full workflow,
including how new keys are generated.
Sys.getenv("ZOTERO_API_KEY") != "", and restart R after
editing .Renviron.