Skip to page navigation menu Skip entire header
Brown University
Skip 14 subheader links

Center for Digital Scholarship

Using the Zotero API to Render Formatted Bibliography on a Webpage

The following documentation describes how the Inscriptions of Israel/Palestine project queries a Zotero collection to retrieve and display bibliographic items. IIP maintains a corpus of inscriptions that are each encoded in a separate XML file according to the Epidoc customization of the TEI schema.

In each inscription, bibliographic citations are encoded as follows:

<listBibl>
 <bibl xml:id="b1"><ptr target="IIP-715"/>
   <biblScope type="insc">154</biblScope>
 </bibl>
 </listBibl>

The ID in the ptr/@target refers to a bibliographic item that is stored in a Zotero collection. We find that using Zotero bibliographic management software makes it easier to manage our bibliography in a collaborative setting and we can leave the work of formatting bibliographic entries to Zotero. The following documentation explains how we use the Zotero API to retrieve full references for reuse in a web page.

Setup:
Youll need a Zotero account (or group) to serve as the home for all your entries. Once logged in to this account, go to your Settings page on the Zotero site and either: Publish your entire library (under Privacy) or Create an API key with library access (under Feeds/API).

Under the Feeds/API tab on the Zotero Settings page, there will be a line telling you what your User ID is for API calls. Make note of this. Also, check the permissions on your API key to make sure you arent allowing write access unless you really want to do that.

Managing citations in Zotero:
Zotero assigns a unique id to each item you store in it, but if you move these items around between collections or users, the IDs change, so they are not reliable for use in external code. Our solution for the Inscriptions of Israel/Palestine was to record our own unique IDs to each citation in the Loc. In Archive Zotero field, and to simultaneously tag each citation with its ID. This is necessary because Zotero only indexes and exposes some fields in the API and Loc. In Archive isnt one of them. The collection will then have as many tags as it has citations.

In the IIP project, each citation in our collection has a project assigned ID, something like IIP-123 in the Loc. in Archive field.For instance, see: https://www.zotero.org/iip/items/itemKey/CRXJ6KJQ, which has a Loc. in ArchiveID and a tag of IIP-715.

Using the Zotero API
(Full documentation: https://www.zotero.org/support/dev/web_api/v3/basics)
Searches for items in the Zotero API look like:

  https://api.zotero.org/users/<USER ID>/items?param=val&param=val

You can also search within a collection:

  https://api.zotero.org/users/<USER ID>/collections/<COLLECTION>/items?param=val

If youre using an API key rather than publishingyour library, you will need to include a &key=... parameter with all your requests, containing the API key you created.

To search for anything containing Darwin in a particular users library, we would request

  https://api.zotero.org/users/<USER ID>/items?q=Darwin

Searching by specific fields in the Zotero API is very limitedyou can only search by title, date, author, and by tag. We use tags so we can refer to citations using our own project IDs. Making the request https://api.zotero.org/users/1604128/items?tag=IIP-715 shows us only items tagged as IIP-715.

By default, Zotero returns results in JSON. We can include a &format=... parameter, to get different formats. For instance, https://api.zotero.org/users/1604128/items?tag=IIP-715&format=bib shows a formatted citation. By default this is a Chicago-style citation, but you can change the style by adding a &style=... parameter. The values for the style parameter are the filenames (without the .csl) from this Zotero page: https://www.zotero.org/styles, e.g. apa or chicago-note-bibliography.

To include multiple citations in one query, we add tag values to the tag parameter and separate them with || and spaces. So tag=IIP-715 || IIP-072 (spaces required) gives us two entries:

https://api.zotero.org/users/1604128/items?tag=IIP-072%20||%20IIP-715&format=bib.

On the IIP results page, we search for many entries at once, but need to know which result matches each ID, so we use format=json and add another parameter, include, to include multiple formats in one query. For IIP, we use format=json and include=bib

https://api.zotero.org/users/1604128/items?tag=IIP-072%20%7C%7C%20IIP-715&format=json&include=bib,data

This returns IIP-072 and IIP-715 as json structures that include a bibliographic citation:

[
    {
        "bib": "<div class=\"csl-bib-body\" style=\"line-height: 1.35; padding-left: 2em; text-indent:-2em;\">\n  <div class=\"csl-entry\">Magen, Yitzhak, Haggai Misgav, and Levana Tsfania. <i>Mount Gerizim Excavations<\/i>. Vol. 1. 2 vols. Jerusalem: Judea & Samaria Publications, 2004.<\/div>\n<\/div>",
        "data": {
            "ISBN": "",
            "abstractNote": "",
            "accessDate": "",
            "archive": "",
            "archiveLocation": "IIP-715",
            "callNumber": "",
            "collections": ["U2J49649"],
            "creators": [
                {
                    "creatorType": "author",
                    "firstName": "Yitzhak",
                    "lastName": "Magen"
                },
                {
                    "creatorType": "author",
                    "firstName": "Haggai",
                    "lastName": "Misgav"
                },
                {
                    "creatorType": "author",
                    "firstName": "Levana",
                    "lastName": "Tsfania"
                }
            ],
            "date": "2004",
            "dateAdded": "2014-11-06T16:14:19Z",
            "dateModified": "2014-11-06T16:14:31Z",
            "edition": "",
            "extra": "",
            "itemType": "book",
            "key": "CRXJ6KJQ",
            "language": "English",
            "libraryCatalog": "",
            "numPages": "272",
            "numberOfVolumes": "2",
            "place": "Jerusalem",
            "publisher": "Judea & Samaria Publications",
            "relations": {},
            "rights": "",
            "series": "",
            "seriesNumber": "",
            "shortTitle": "",
            "tags": [{"tag": "IIP-715"}],
            "title": "Mount Gerizim Excavations",
            "url": "",
            "version": 3946,
            "volume": "1"
        },
        "key": "CRXJ6KJQ",
        "library": {
            "id": 1604128,
            "links": {"alternate": {
                "href": "https://www.zotero.org/iip",
                "type": "text/html"
            }},
            "name": "IIP",
            "type": "user"
        },
        "links": {
            "alternate": {
                "href": "https://www.zotero.org/iip/items/CRXJ6KJQ",
                "type": "text/html"
            },
            "self": {
                "href": "https://api.zotero.org/users/1604128/items/CRXJ6KJQ",
                "type": "application/json"
            }
        },
        "meta": {
            "creatorSummary": "Magen et al.",
            "numChildren": 0,
            "parsedDate": "2004"
        },
        "version": 3946
    },
    {
        "bib": "<div class=\"csl-bib-body\" style=\"line-height: 1.35; padding-left: 2em; text-indent:-2em;\">\n  <div class=\"csl-entry\">Lifshitz, Baruch. Greek Inscriptions from Eretz Israel. <i>Bulletin of the Israel Exploration Society (=Yediot)<\/i> 22 (1958): 6273.<\/div>\n<\/div>",
        "data": {
            "DOI": "",
            "ISSN": "",
            "abstractNote": "",
            "accessDate": "",
            "archive": "",
            "archiveLocation": "IIP-072",
            "callNumber": "IIP-072",
            "collections": ["U2J49649"],
            "creators": [{
                "creatorType": "author",
                "firstName": "Baruch",
                "lastName": "Lifshitz"
            }],
            "date": "1958",
            "dateAdded": "2013-10-16T14:47:52Z",
            "dateModified": "2013-10-16T14:47:52Z",
            "extra": "",
            "issue": "",
            "itemType": "journalArticle",
            "journalAbbreviation": "BIES",
            "key": "PTQMKJKP",
            "language": "Hebrew",
            "libraryCatalog": "",
            "pages": "62-73",
            "publicationTitle": "Bulletin of the Israel Exploration Society (=Yediot)",
            "relations": {},
            "rights": "",
            "series": "",
            "seriesText": "",
            "seriesTitle": "",
            "shortTitle": "",
            "tags": [
                {"tag": "Beth Shearim"},
                {"tag": "IIP-072"}
            ],
            "title": "Greek Inscriptions from Eretz Israel",
            "url": "",
            "version": 2169,
            "volume": "22"
        },
        "key": "PTQMKJKP",
        "library": {
            "id": 1604128,
            "links": {"alternate": {
                "href": "https://www.zotero.org/iip",
                "type": "text/html"
            }},
            "name": "IIP",
            "type": "user"
        },
        "links": {
            "alternate": {
                "href": "https://www.zotero.org/iip/items/PTQMKJKP",
                "type": "text/html"
            },
            "self": {
                "href": "https://api.zotero.org/users/1604128/items/PTQMKJKP",
                "type": "application/json"
            }
        },
        "meta": {
            "creatorSummary": "Lifshitz",
            "numChildren": 0,
            "parsedDate": "1958"
        },
        "version": 2169
    }
]

You can see two separate objectsone for each tagand each object includes two fields, data, and bib. bib is a formatted citation, and data is all the data entered for that item in Zotero (including its tags).

For the actual IIP results page (http://dlibwwwcit.services.brown.edu/cds/projects/iip/results/?q=*:*), each inscription has its own list of bibliographical entries; these are preserved as IDs in each inscription. When an inscription is displayed, we generate a javascript query to replace these IDs in the browser with formatted citations and a link to the Zotero entry. You may notice the slight delay or see

Source of Translation: IIP-145|page|4

turn into

Source of Translation: Schwabe. Beth She'arim. Vol. 2, The Greek Inscriptions, 1974: 4 (Full)

Whenever an inscription is opened, the IDs in the Source Of display fields (<bibl> in the XML source) are used to make a request to Zotero to retrieve the proper citation.

This postas well as the IIP code were written by Carlos Rotger ’17.
Also of interest: Annotated Bibliography in Scalar using Zotero