Tag Archives: Zotero

Insert Zotero bibliographic data into a web-page by querying the Zotero API

  1. Figure out your Zotero user id. This is not the same as your Zotero username. Log into your Zotero account at www.zotero.org. Settings > Feeds/API. Copy the value given by “Your userID for use in API calls is … “.
  2. Construct an API query URL that gives you the bibliographic data you need in the format you want it. Documentation.
    • The URL starts with https://api.zotero.org/users/<userid>/.
    • For a single bibliographic item, add items/<itemkey>. To discover the item key, see the HowTo on this page.
    • Item example: https://api.zotero.org/users/160881/items/8HTNV32W/?v=3&format=bib&style=elsevier-harvard2. 160881 is my user id. 8HTNV32W is the item id in my Zotero database. v=3 selects the most recent API version number (i.e. ver. 3). format=bib requests that the data be formatted as an XHTML bibliography. style=elsevier-harvard2 sets the citation style. I like elsevier-harvard2 because 1/ it doesn’t pointlessly capitalize all title words, and 2/ it doesn’t italicize Chinese (or any) titles. See the result returned by this URL here.
    • Multiple item example: https://api.zotero.org/users/160881/items/?v=3&format=bib&style=elsevier-harvard2&itemKey=UDAKWEPD,6MPC3NRH,BETZ6T8M,2A44Q48D,9KDGT7VK,24MN76X3,IFITWC8S,5JKVSN7X,DSF26IDM,2W76QV2C,983IUQW6,5IBA73W6. Notice that the item keys are now a comma-separated list in the query string. Result is here.
    • Tag example: to return a bibliography of all items with a particular tag use tag= in the query string. E.g. https://api.zotero.org/users/160881/items/?v=3&format=bib&style=elsevier-harvard2&tag=OBI. Result is here. For more complocated tag queries, see the Documentation.
    • COinS: By changing the format=bib to format=coins, a set of <span>s containing COinS data is returned instead. https://api.zotero.org/users/160881/items/?v=3&format=coins&tag=OBI.
  3. Adding the bibliograpic data to a php/html webpage is simple:
    $url = 'https://api.zotero.org/users/160881/items/?v=3&format=coins&tag=OBI';
    $var = file_get_contents($url);
    echo $var;

Get Zotero item key from Firefox

To read an item via the Zotero API, you need to have the item key. Oddly, the Zotero Firefox app does not provide simple access to the item keys. The following export translator will copy the item keys as a comma-separated list to the clipboard on Ctrl+Shift+c in the usual manner. The translator needs to be saved as a javascript file (.js file extension) in the Zotero translators directory. My translators directory was here ~/.mozilla/firefox/wgcm6dkk.default/zotero/translators/. The code is based on that found here: https://gist.github.com/nschneid/3134386, but pared down to give nothing apart from the list of item keys.

"label":"Zotero Item Key",
"creator":"Adam Smith",
"lastUpdated":"Fri 22 Aug 2014 12:24:20 PM EDT"

function doExport() {
   var item;
   if(item = Zotero.nextItem())
   while(item = Zotero.nextItem())