Skip to content

Instantly share code, notes, and snippets.

@omundy
Last active August 18, 2021 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omundy/ba88b91b5eea1734c489b18b588f777b to your computer and use it in GitHub Desktop.
Save omundy/ba88b91b5eea1734c489b18b588f777b to your computer and use it in GitHub Desktop.

Zotero API Notes

Links and sample code to access data in Zotero

Links

Javascript & SQL in the editor

In Zotero Beta, Tools > Developer > Run Javascript

Javascript > Display fields from selected references 🚫 async

var items = Zotero.getActiveZoteroPane().getSelectedItems();
var arr = [];
for(var i=0; i<items.length; i++){
    arr.push({
        title: items[i].getField('title'),
        url: items[i].getField('url')
    });
}
JSON.stringify(arr,null,2);

SQL > Display all creators ✅ async

var sql = `
  SELECT DISTINCT TRIM(firstName || ' ' || lastName) AS creator 
  FROM creators 
  WHERE creatorID IN (
      SELECT creatorID FROM itemCreators JOIN items USING (itemID) WHERE libraryID=1
  ) ORDER BY creator`;
var names = await Zotero.DB.columnQueryAsync(sql);
return names.join('\n');

Next up... https://github.com/tnajdek/zotero-api-client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment