Write API usage examples

Please could you show the usage of the sample code as provided in the write API page. The read examples are straight forward since I only need to pad the URL details for the user and userid and define what I need to read i.e. items and all that goes in the URL and easily pasted to a browser or in code, can call up an iframe with the source URL.

I am developing in java and would need to dynamically create entries to my zotero account as a placeholder of things I need to search citations for, hence an example say on how to create a note in a given category will set me in the right path.



Emma Cox
  • the docs have an example for creating an item:
    also, you can look at the existing libraries or apps developed based on the API: http://www.zotero.org/support/dev/server_api#api_implementations
  • edited January 24, 2013
    Thanks Adam,
    My problem is how would I make use of the code snippets show in the write API page, The penny hasn't dropped yet for me on where the code is to appear.
    Do I have that in the URL?

    How do I define the name of the note, and if I have multiple categories, How do I create categories first. I know I will kick myself when I am shown how easy this is achieved, so preparing a nice pair of boots for that, but until then, itching to slap myself for on not seeing the obvious.
  • You need to make several calls (GET and POST) to create notes. You also need some kind of HTTP library to make the calls.

    1) First you would need to do a GET request to get a template for a new item. This is returned as JSON, so you need a parser that will parse the JSON string as java objects (arrays and dictionaries).


    2) Then modify the object properties so that they match your note content and use the JSON library to convert the objects back to JSON string. Then POST this to the server


    3) You will get the item id as a response. Then you need to do a third call to add that item id to a collection with another POST call

  • Thanks mronkko.
    Heavy lifting this appears to be for write operations, being not very clued up on programming, appears will be more reading for me.
  • edited January 24, 2013
    FWIW, codeacademy has a series of (free) courses on API in both python and javascript, I haven't tested them, but might be a good way to get acquainted with the general idea beyond URL requests.

  • I have exhausted my little knowhow in programming and would like to seek assistance with this task. Anyone ready to assist me getting this sorted in Java?
  • you can try zotero-dev https://groups.google.com/forum/?fromgroups=#!forum/zotero-dev
    but this is much more likely to be successful if you have specific questions based on existing code. Something like "how do I make a GET request in Java" is too general of a question for a limited resources listserv like Zotero's and you'd probably want to go somewhere with a deeper bench lik stackoverflow or some other general code site.
    The general way the Zotero API works is no different from most other APIs.
  • In Wavemaker, I have managed to create java classes to perform a GET operation and in firebug debugger, I can see the Post, Response and JSON containing as follows

    {"result":"null<?xml version=\"1.0\"?><feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:zapi=\"http://zotero.org/ns/api\"> <title>Zotero / eomc40 / Items</title> <id>http://zotero.org/users/1269166/items/new?itemType=book</id>; <link rel=\"self\" type=\"application/atom+xml\" href=\"https://api.zotero.org/users/1269166/items/new?itemType=book\"/> <link rel=\"first\" type=\"application/atom+xml\" href=\"https://api.zotero.org/users/1269166/items/new?itemType=book\"/> <link rel=\"last\" type=\"application/atom+xml\" href=\"https://api.zotero.org/users/1269166/items/new?itemType=book\"/> <link rel=\"alternate\" type=\"text/html\" href=\"http://zotero.org/users/1269166/items/new?itemType=book\"/> <zapi:totalResults>1</zapi:totalResults> <zapi:apiVersion>1</zapi:apiVersion> <updated>2013-01-29T12:50:15Z</updated> <entry xmlns:default=\"http://www.w3.org/1999/xhtml\"> <title>My Nifty Book Title</title> <author> <name>eomc40</name> <uri>http://zotero.org/eomc40</uri>; </author> <id>http://zotero.org/eomc40/items/47NPQRV2</id>; <published>2013-01-29T12:50:15Z</published> <updated>2013-01-29T12:50:15Z</updated> <link rel=\"self\" type=\"application/atom+xml\" href=\"https://api.zotero.org/users/1269166/items/47NPQRV2\"/> <link rel=\"alternate\" type=\"text/html\" href=\"http://zotero.org/eomc40/items/47NPQRV2\"/> <zapi:key>47NPQRV2</zapi:key> <zapi:itemType>book</zapi:itemType> <zapi:creatorSummary>Aron BeJesus</zapi:creatorSummary> <zapi:year/> <zapi:numChildren>0</zapi:numChildren> <zapi:numTags>0</zapi:numTags> <content zapi:type=\"html\" type=\"xhtml\"> <default:div xmlns=\"http://www.w3.org/1999/xhtml\"> <table> <tr class=\"itemType\"> <th style=\"text-align: right\">Type</th> <td>Book</td> </tr> <tr class=\"creator\"> <th style=\"text-align: right\">Contributor</th> <td>Aron BeJesus</td> </tr> <tr class=\"abstractNote\"> <th style=\"text-align: right\">Abstract</th> <td>A very nice book</td> </tr> </table> </default:div> </content> </entry></feed>"}

    As per the point notes by Mronkko, I need assistance to perform item 1, since I don't understand what needs to be gathered from this data to get the "template" that is needed for the next steps.

    I am new to programming and just need a guiding hand to understand how the bolts and nuts fit together.
  • Please post to zotero-dev list, as instructed by adamsmith.

    When you post code, use a code posting service such as gist.github.com and format the code to be readable.
  • The API implementations on https://www.zotero.org/support/dev/web_api/v2/start are useful to get started with the API, and have examples.
  • I also wrote this, which I intended to move Zandy to: https://github.com/ajlyon/libzotero-java

    It is a pure Java wrapper of the Zotero API, albeit an incomplete one.
Sign In or Register to comment.