Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:api_user_docs [2010/04/01 20:10] kddev:api_user_docs [2017/11/12 19:53] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Zotero API documentation ======+<html><p id="zotero-5-update-warning" style="color: red; font-weight: bold">We’re 
 +in the process of updating the documentation for 
 +<a href="https://www.zotero.org/blog/zotero-5-0">Zotero 5.0</a>. Some documentation 
 +may be outdated in the meantime. Thanks for your understanding.</p></html>
  
-This documentation is a work in progress, and at this stage you see many TODO entries in the list.  There are also things I haven't thought of.  If you end up writing code that interacts with the Zotero API, please consider adding to the list below so that source-diving within the zotero XPI can become a thing of the past. 
- 
-===== Setting up a simplified development environment ===== 
- 
-The two easiest ways to set up a development environment for Zotero is either with an interactive javascript environment, or using The Firefox extension [[http://davidkellogg.com/wiki/Main_Page|Plain old Webserver]] which runs a web server inside of Firefox.  Plain old Webserver can use server side Javascript to dynamically create pages, and as such all of the Zotero internals are accessible to code running within this web server. 
- 
-There are a number of suitable interactive javascript environments for interacting with Firefox's internals (FireBug is not suitable).  The suitable extensions that I have been able to find are: 
- 
-  - [[http://wiki.github.com/bard/mozrepl/|MozRepl]], an interactive shell available by telnetting to localhost on port 4242 (by default).  Linux and Mac OS X users can use the built in telnet client.  Windows users should use [[http://www.chiark.greenend.org.uk/~sgtatham/putty/|Putty]]. 
-  - A Firefox plugin to provide MozRepl access [[http://ubik.cc/2009/09/mozrepl-in-a-panel.html|directly inside firefox ]]. 
-  - The [[https://addons.mozilla.org/en-US/firefox/addon/1729|ExecuteJS]] extension. 
- 
-My feeling is that the easiest way to get some kind of working application up is to use the Plain old Webserver and server side javascript.  This also makes it relatively easy to deploy code to other users without going to the trouble of creating a whole new firefox extension. 
- 
-Setting up a Firefox development environment is beyond the scope of this 
-document. 
- 
-Perl programmers should be aware of the [[http://search.cpan.org/perldoc?MozRepl|MozRepl]] CPAN module, and the closely 
-related [[http://search.cpan.org/perldoc?MozRepl::RemoteObject|MozRepl::RemoteObject]] which allows you to access Javascript objects 
-from inside perl programs. 
- 
-**A problem with MozREPL**: With a longer script I've had trouble with MozRepl timing out on me for no apparent reason.  The solution to this is to either send the code to the terminal application in smaller sized chunks, or to keep pasting the code in until it works. Unfortunately in some cases missing semicolons and curly brackets can cause silent failure in the REPL as well which means that debugging longer bits of code can be interesting.  Avoid this by avoiding excessively long blocks of procedural code - factor everything into smaller functions wherever possible. 
- 
-===== Zotero API Howtos ===== 
- 
-The Zotero API is under-documented, and at present requires a lot of looking around in the source code.  The most useful parts of the source code are in chrome/content/zotero/xpcom and xpcom/data, and the chrome/content/zotero (particularly overlay.js and fileInterface.js) 
- 
-==== Create new Zotero object ==== 
- 
-This is the first thing that you need to do when interacting with zotero's 
-internals.  The code to do so is: 
- 
-''    var Zotero = Components.classes["@zotero.org/Zotero;1"] .getService(Components.interfaces.nsISupports).wrappedJSObject; 
-'' 
- 
-==== Setup a Zotero search ==== 
- 
-If you are focused on data access, then the first thing you will want to do 
-will be to retrieve items from your zotero.  Creating an in-memory search is a 
-good start. 
- 
-''    var search = new z.Search();'' 
- 
-====  Search for items containing a specific tag ==== 
- 
-Starting with the code from "Setup a Zotero search" we then use the following 
-code to retrieve items with a particular tag: 
- 
-''    search.addCondition('tag', 'is', 'tag name here');'' 
- 
-==== Search for a Zotero subcollection ==== 
- 
-TODO 
- 
-==== Select a Zotero saved search ==== 
- 
-TODO 
- 
-==== Search term operators ==== 
- 
-TODO 
- 
-==== Combining search terms ==== 
- 
-TODO 
- 
-==== Complete list of search operators ==== 
- 
-TODO (should be pretty easy) 
- 
-==== Complete list of search fields ==== 
- 
-TODO (with description of what the more obscure fields mean - e.g. abstractNote for 
-abstract, and how do we search the fulltext archive?) 
- 
-==== Executing the search ==== 
- 
-Once the search conditions have been set up, then it's time to execute the 
-results: 
- 
-''    var results = search.search();'' 
- 
-This returns the item ids in the search as an array [I could be wrong ... ]. 
-The next thing to do is to get the Zotero items for the array of IDs: 
- 
-''    var items = z.Items.get(results);'' 
- 
-==== Getting a bibliography for an array of items: ==== 
- 
-Here we use zotero's quickcopy functions to get a bibliography in the style 
-specified in Zotero's preferences. 
- 
-First we start with a list of as in the previous entry. 
- 
-''  var qc = z.QuickCopy; 
-  var biblio = qc.getContentFromItems(new Array(item), 
-                                      z.Prefs.get("export.quickCopy.setting")); 
-    var biblio_html_format = cite.html; 
-    var biblio_txt         = cite.text; '' 
- 
-TODO:  get citations.  change the style.  get stuff in other formats, 
-especially RTF 
- 
-==== Get information about an item. ==== 
- 
-TODO:  need to list all the possible fields here, and what kind of entry they 
-belong to. 
- 
-To get an item's abstract, we get the 'extra' field from the Zotero item: 
- 
-''    var abstract = item.getField('extra'); '' 
- 
-==== Get fulltext for an item. ==== 
- 
-TODO 
- 
-==== Get stored attachements for an item ==== 
- 
-TODO 
- 
-==== Get child notes for an item ==== 
- 
-To get the child notes for an item, we use the following code: 
- 
-''    var notes = item.getNotes(); '' 
- 
-This returns an array of notes.  Each note is in HTML format.  To get each note 
-in turn we just iterate through the array: 
- 
-''    for (var j=0;j<notes.length;j++) { 
-        var note = z.Items.get(notes[j]); 
-        var note_html = note.getNote; 
-    } '' 
- 
-==== Get an item's related items ==== 
- 
-This technique works for anything that can have related items attached within 
-the zotero database.  This includes items and notes. 
- 
-''  var related_items = item.relatedItemsBidirectional '' 
- 
-This returns a list of items just like in the search examples. 
- 
-=====  Generic XUL Javascript to provide support functions ===== 
- 
-==== Writing out a file: ==== 
- 
-This function will write out a file to a specified filename.  If the file 
-already exists it will be silently overwritten.  [TODO: obviously this needs to 
-be cleaned up, talk about append mode as well, and failure if file already 
-exists ...] 
- 
-Note that Plain Old Webserver contains quite a few simplified support functions for reading, writing and deleting files, including new bits of javascript, and generally making things nice and easy. 
- 
- 
-''  function writeFile(filename, data)    { 
-      var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); 
-      var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream); 
-      file.initWithPath(filename);  
-      foStream.init(file, 0x02 , 00666, 0); 
-      foStream.write(data, data.length); 
-      foStream.close(); 
-  }; 
- 
-  writeFile("/tmp/boo.txt", "boo\n"); '' 
- 
-==== TODO ==== 
- 
-many other things :) 
  
 +See [[dev/client_coding/JavaScript API]].
dev/api_user_docs.1270167042.txt.gz · Last modified: 2010/04/01 20:10 by kd