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:
    <?php 
    $url = 'https://api.zotero.org/users/160881/items/?v=3&format=coins&tag=OBI';
    $var = file_get_contents($url);
    echo $var;
    ?>
    

Leave a Reply

Your email address will not be published. Required fields are marked *