Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-13-2009, 10:05 AM
Junior Member
 
Posts: 5
Default [SOLVED] REST -ful way to list calendars?

I'd like to build an app for our Zimbra users to add individual events from some non-Zimbra public calendars to their Zimbra calendars.

Using the migration guide, I can see how to use curl to upload an event to a user's calendar (given their username/password, which the app will have access to).

But the question now is *which* calendar to add the event too?

Another thread indicates that an administrator can do this sort of thing...
zmmailbox -z -m <account> gaf

Is there a REST -ful way to get such a list of calendars?
Reply With Quote
  #2 (permalink)  
Old 05-19-2009, 11:59 AM
Member
 
Posts: 10
Default

I don't think this is exactly what you're asking for, but here's a good example of a REST url for a "non-standard" calendar that we use (shared company calendar). This one was to deliver the ICS version of said calendar to another application.

https://mail.ourcompany.com/service/...lendar?fmt=ics

So, in this sample, the calendar's name in Zimbra was shown as:

"Our Company Calendar" which is given in the REST url as "our%20company%20calendar" (without quotes, of course).

This works bi-directionally for adding, removing and changing events from another application for a specific calendar in Zimbra, so I thought it might point you in the right direction. Hope this helps!
Reply With Quote
  #3 (permalink)  
Old 05-20-2009, 06:02 AM
Junior Member
 
Posts: 5
Default

This is good stuff. But what I still need is a REST-ful way to find out what all the possible calendar names are.
Reply With Quote
  #4 (permalink)  
Old 02-02-2010, 10:35 AM
Member
 
Posts: 14
Default

Hi paumr, did you ever find a way of doing this? I'm trying to do the same thing. Any help much appreciated!
Reply With Quote
  #5 (permalink)  
Old 02-02-2010, 11:55 AM
Zimbra Employee
 
Posts: 105
Default

You can use the <GetFolderRequest> SOAP command and that will return a list of folders. The folders with view="appointment" are calendar folders.

Submit the <GetFolderRequest xmlns="urn:zimbraMail" /> request and get the response and parse the response for view="appointment" for calendar folders.

Code:
<GetFolderResponse xmlns="urn:zimbraMail">
<folder>........</folder>
<folder>........</folder>
<folder view="appointment" i4ms="307" ms="307" i4next="587" l="1" id="586" rev="307" color="1" f="#" n="0" name="myholidaycalendar" rgb="#9EB6F5" s="0"/>
<folder i4ms="306" view="appointment" ms="1" f="#" i4next="585" n="15" l="1" name="Calendar" s="0" id="10" rev="1"/>
<folder>........</folder>
<folder>........</folder>
<folder>........</folder>
</GetFolderResponse>
Now your next question is: I don't want to have to call SOAP, can I do this without SOAP? Yes.

You can just submit the SOAP formatted XML to the server SOAP URL. And read the XML response. That does not require SOAP or a SOAP library, so you can call it from anywhere.

For example, to do this thru Java, you can make a URL connection to the SOAP URL, post the XML content and read the response. The follow shows submitting SOAP XML to a URL without the use of a SOAP toolkit or any Zimbra-specific SOAP Java libraries...it's just plain-ol' Java:

Code:
String SOAPUrl      = "http://localhost:7070/service/soap/";

// Create the connection where we're going to send the file.
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;

String	postContent = "<soap>....</soap>"; // insert your SOAP XML!!!
byte[] b = postContent.getBytes();

// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length", String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","application/soap+xml; charset=utf-8");
httpConn.setRequestMethod( "POST" );
httpConn.setDoOutput(true);
httpConn.setDoInput(true);

// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();
out.write( b );    
out.close();

// Read the response and write it to standard out.
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);

// read & do something with input stream...

in.close();
Now what does a SOAP XML format look like? Here's a sample of making the <GetFolderRequest>. Be sure to replace the auth token with your auth token (from the ZM_AUTH_TOKEN cookie...or use the <AuthRequest> SOAP command to generate an auth token:

Code:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<context xmlns="urn:zimbra">
<format xmlns="" type="xml"/>
<authToken xmlns="">XXX_XXXX_XXXX</authToken>
</context>
</soap:Header>
<soap:Body>
<GetFolderRequest xmlns="urn:zimbraMail" />
</soap:Body>
</soap>
So it's not "REST" per se but it's a way of calling into Zimbra via URL and no external libraries required. You submit content to a URL and read a response. That's about it.

Note: you can do the same thing and submit JSON (instead of XML) and get a JSON response (instead of XML) if that format works better for you. See ZimbraServer/docs/soap.txt for more information on these commands and the SOAP API in general.

Also, if you want to test-out the SOAP commands, you can use the ZmSoap utility that is part of ZCS.

Zmsoap - Zimbra :: Wiki
Reply With Quote
  #6 (permalink)  
Old 02-02-2010, 11:55 AM
Junior Member
 
Posts: 5
Default

No, I never did find out how to query all calendar names via REST.

Our organization gives each user a calendar called "calendar", so I had my app add the event to that one, because I know it must exist.

But it would still be nice to be able to allow users to add events to calendars that they've set up themselves.
Reply With Quote
  #7 (permalink)  
Old 02-02-2010, 12:08 PM
Junior Member
 
Posts: 5
Default

Sposetti,

Cool! Yes, that's exactly the sort of thing I was hoping to do. And yes, I wanted a non-SOAP way of doing it :->
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.