I'm attempting to quickly find free/busy time by fetching the calendar events for an iCloud calendar via CalDAV. I'm able to get the available calendars, and according to documentation here or using the DAViCal client library fetching the calendar information for a given date range should be as simple as sending this REPORT xml request to a calendar URL (ie. https://caldav.icloud.com/..userid../calendars/work/):
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:prop>
<d:getetag />
<c:calendar-data />
</d:prop>
<c:filter>
<c:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20131115T000000Z" end="20131201T000000Z"/>
</C:comp-filter>
</c:comp-filter>
</c:filter>
</c:calendar-query>
which is essentially what the GetEvents()
function does in the DAViCal library. However I'm just getting the URL for each calendar entry in the reply, rather than the calendar data itself:
<?xml version='1.0' encoding='UTF-8'?><multistatus xmlns='DAV:'>
<response>
<href>/..userid../calendars/work/8D2D90EB-BD23-4137-AD22-70D971C587F2.ics</href>
<propstat>
<prop>
<getetag>"C=7734@U=b09ce345-d654-491e-bb4a-55358e7019d9"</getetag>
<getcontenttype>text/calendar</getcontenttype>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/..userid../calendars/work/AA2385AB-EA58-4625-AF87-6D4FB9405686.ics</href>
<propstat>
<prop>
<getetag>"C=7733@U=b09ce345-d654-491e-bb4a-55358e7019d9"</getetag>
<getcontenttype>text/calendar</getcontenttype>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
...
</multistatus>
I can of course do a GET request for each individual calendar item, but obviously this is quite slow. Is there a trick to getting the calendar data downloaded in one request?
It works if you just include
<c:calendar-data />
and NOT
<d:getetag />
in the request, like this:
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:prop>
<c:calendar-data />
</d:prop>
<c:filter>
<c:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20131115T000000Z" end="20131201T000000Z"/>
</C:comp-filter>
</c:comp-filter>
</c:filter>
</c:calendar-query>
:-)