How do you add a collection via tha API in Java?

45 views
Skip to first unread message

Doug G.

unread,
Oct 24, 2012, 1:35:19 PM10/24/12
to zoter...@googlegroups.com
All,

I am new to OAuth and I can't figure out how to post data.  The documentation on the zotero site says:

Creating a Collection

POST /users/1/collections
Content-Type: application/json
X-Zotero-Write-Token: 19a4f01ad623aa7214f82347e3711f56

{
  "name" : "My Collection",
  "parent" : "QRST9876"
}


Now what?  Here is what I have:

String str_json = "{\"name\" : \"" + folder_name + "\", \"parent\" : false}";

String apiUrl = "https://api.zotero.org/users/" + userId + "/collections?key="+secret;
URL url = new URL(apiUrl);
HttpURLConnection request = (HttpURLConnection) url.openConnection();
request.setRequestProperty("Content-Type","application/json");
request.setRequestProperty("collection",str_json);
consumer.sign(request);
request.connect();

return_value = convertStreamToString(request.getInputStream());

System.out.println(return_value);

The "return_value" is just the folders that all ready exist.  How and what data do I post?  Any help would be appreciated.

Note:
I also tried encoding the JSON string and attaching it to the URL.  That didn't change the result.

Thanks,
Doug.


Rönkkö Mikko

unread,
Oct 24, 2012, 1:53:03 PM10/24/12
to <zotero-dev@googlegroups.com>
Hi

You need to create an API key with oAuth. If you want an easy solution, you can also generate a key at 


If you are working on an enduser application, then oAuth provides a way to create keys automatically.

Mikko

--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/zotero-dev/-/c9RO-6XF930J.
To post to this group, send email to zoter...@googlegroups.com.
To unsubscribe from this group, send email to zotero-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/zotero-dev?hl=en.

Doug G.

unread,
Oct 24, 2012, 2:18:56 PM10/24/12
to zoter...@googlegroups.com
I all ready have a key.  I can use the "read" API fine.  My challenge is posting data.  If you look at the create collection under the Write API it tells you to post certain data.  I'm not sure how to post data using OAuth and I'm not sure what I need to post for the JSON.  Do I set the parameter to collection={MY JSON}?
To post to this group, send email to zote...@googlegroups.com.
To unsubscribe from this group, send email to zotero-dev...@googlegroups.com.

Rönkkö Mikko

unread,
Oct 24, 2012, 2:33:22 PM10/24/12
to <zotero-dev@googlegroups.com>
OAuth is used to create the key. You do not need it after that.

So is your question is how to post? You need to post the json string in the body of the post request, not in the headers like you are attempting. I am not a Java programmer, so cannot say how this is done with Java, but you can probably find plenty of examples with google.


To view this discussion on the web visit https://groups.google.com/d/msg/zotero-dev/-/9C2gvXhRK3EJ.
To post to this group, send email to zoter...@googlegroups.com.
To unsubscribe from this group, send email to zotero-dev+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages