Monday, May 18, 2009

Dealing with Zotero collections

Zotero offers some nice API functions for collection management.

  • Zotero.Collections() return an array to all the collections in the current library. I am not sure how this will handle shared collections but it is worth investigation.
  • Zotero.Collection is an object that will handle everything related to a Zotero collection. 
To add a new collection, one can:
  • Add the row directly to the DB. A dirty solution that used to work for version 1.* until 1.5 beta. However, it stopped working with version 2.* (the beta version at least) because the key field in collections table can not be empty anymore.
  • Use Zotero.Collections.Add(__collection_name__) and reference the new object 
//
// Create a Zotero collection object
//
newCollection = new Zotero.Collection();

To add items to a collection, the direct DB query is still working but I would not advise you to use it as it will break the stability of the DB sometimes. So the better approch is to use Collection.addItem() or Collection.addItems() methods.
newCollection.addItem(duplicateItemID);

No comments: