2

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!

Klerafukan
  • 53
  • 6
  • It seems to work if I use the URI: `https://caldav.icloud.com/1722222111/calendars/` However is only one collection allowed and I want to at least create three calendars. I am not sure how to access or create a new URI for those calendars. As I mentioned, it used to work with generation a UUID and just concatenate the UUID to the calendar URI. – Klerafukan Nov 15 '18 at 14:37

2 Answers2

2

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.

Community
  • 1
  • 1
hnh
  • 13,957
  • 6
  • 30
  • 40
  • Good point. I will do that. So far I can't seem to do the PROPFIND request on the https://caldav.icloud.com/principle/. It always returns a 404 "not foud". But I will figure it out. – Klerafukan Nov 30 '18 at 09:17
  • Ok just a last statement to finish this: I implemented the discovery approach and a workaround for the bug. Everything works fine! I thank you guys a lot!!! Til – Klerafukan Dec 05 '18 at 08:23
  • Would you mind marking this answer as the one then? The accepted one may work, but it is a non-conforming hack that will break as soon as they fix it ... – hnh Dec 05 '18 at 09:35
  • I marked the second answer. Because I agree that this is best practice. However my problem solves solution 1. I hope Apple will fix this bug soon and I can remove my workaround. – Klerafukan Dec 06 '18 at 10:18
  • If the hack is required, it sounds that we don't have a proper answer yet. When I do a MKCALENDAR in Calendar.app and look in the Charles trace, it makes a proper request and succeeds. Now that could be due to user-agent sniffing, not sure. – hnh Dec 06 '18 at 12:48
1

If you use https://pXX-caldav.icloud.com/123456789/calendars/new-calendar-name-or-href/ for making MKCOL request, then you will get 201 CREATED status and the href of your new collection will be pXX-caldav.icloud.com/123456789/calendars/new-calendar-name-or-href/

teymourlouie
  • 6,645
  • 2
  • 21
  • 13
  • I could kiss you right now!! Thank you so much. Is there any way that is documented somewhere? – Klerafukan Nov 19 '18 at 15:32
  • Unfortunately, the most problem with iCloud is lack of documentation. I found the answer by some try and error. – teymourlouie Nov 20 '18 at 10:01
  • That would be a straight bug though and should be Radar'ed: http://radar.apple.com – hnh Nov 26 '18 at 22:50
  • "Unfortunately, the most problem with iCloud is lack of documentation" - the CalDAV protocol is a proper standard w/ a complete RFC and plenty of documentation! – hnh Nov 26 '18 at 23:24
  • Thanks for your comment, actually the url I provided in my comment was wrong and I corrected it. as I said, I have to send MKCOL request to https://pXX-caldav.icloud.com/123456789/new-calendar-name-or-href/ to create a new calendar at http://pXX-caldav.icloud.com/123456789/calendars/new-calendar-name-or-href/. – teymourlouie Nov 28 '18 at 09:42
  • @hnh a few days ago, Apple changed it's implementation (fixed the bug) and creating new calendar via https://pXX-caldav.icloud.com/123456789/new-calendar-name-or-href/ is not working anymore. it should be https://pXX-caldav.icloud.com/123456789/calendars/new-calendar-name-or-href/ ;) – teymourlouie Jun 18 '20 at 05:13