Search code examples
icloudcaldavhttp-status-code-412

CalDav Client for iCloud: MKCOL fails with 412 precondition failed


I need help. I implemented a CalDav Client on our System and it worked like a charm. Now I have some problems with creating new calendars on iCloud. Maybe some of you know how I can fix this.

Currently I get a 412 Error.

Headers:

"Depth: 1"
"Content-Type: application/xml; charset=UTF-8"
"User-Agent: DAVKit/4.0.1 (730); CalendarStore/4.0.1 (973); iCal/4.0.1 (1374); Mac OS X/10.6.2 (10C540)"`

Request:

`MKCOL`

Body:

    <D:mkcol xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"> 
    <D:set>
      <D:prop>
        <D:resourcetype>
          <D:collection/>
          <C:calendar-collection/>
       </D:resourcetype>"
       <D:displayname>some name</D:displayname>
      </D:prop>
    </D:set>
    </D:mkcol>`

URL:

https://caldav.icloud.com/1722222111/calendars/64DA8FE9D95A40E4B83A45B47DEC6C53/

The URL ist my Principle (I changed it of course) and a randomly generated UUID for the calendar resource.

Maybe somebody spots any errors? Used to work fine 6 months ago.

Thank you very much!


Solution

  • While there seems to be a mapping bug on the caldav.icloud.com endpoint (filed that as Radar 46258347 if you want to refer), you are not supposed to hit a /calendars URL on this endpoint in the first place.

    You only use caldav.icloud.com to discover the principal resource (representing the user/account). This contains the actual partition hosting the caldav server for your account, it looks like:

    https://pXX-caldav.icloud.com/asdfjasdjkjfd/calendars/
    

    Those endpoint still seem to work just fine (just tried).

    So how do you get from caldav.icloud.com to the actual CalDAV server? You need to retrieve the calendar-home-set property of the principal.

    The whole process is described in the CalDAV RFC or in this nice guide: http://sabre.io/dav/building-a-caldav-client/#discovery.