6

I've been trying to recieve the iCloud contacts related to my Apple Id, but for some reason it doesn't work. I'm getting a (404) Not Found error.

I know iCloud uses CardDAV and that you need a specific URL address in order to access your Contacts.

For the CardDAV client I used the following: https://github.com/Metric/CardDavNet For the server address I tried multiple url's (ofcourse MYUSERID is my real user id):

https://p02-caldav.icloud.com/MYUSERID/carddavhome/card/ https://p02-contacts.icloud.com/MYUSERID/carddavhome/card/

What am I doing wrong? Am I using the correct server URL's or is there something else wrong? I hope someone can guide me into the right direction.

Mittchel
  • 1,896
  • 3
  • 19
  • 37

1 Answers1

3

The second URL you mention looks kinda OK. But to reliably get the URL which hosts your address book, you need to query the addressbook-home-set property of the principal record of your account.

Like:

PROPFIND Depth:0 /12345/principal/
<propfind xmlns="DAV:">
  <prop>
    <addressbook-home-set xmlns="urn:ietf:params:xml:ns:carddav"/>
  </prop>
</propfind>

and to find the principal, you query for the 'principal-URL' property, e.g. on /, with your auth set:

PROPFIND Depth:0 /
<propfind xmlns="DAV:">
  <prop><principal-URL/></prop>
</propfind>

You might also want to use a debugging proxy like Charles or Fiddler to figure out what your .NET framework is actually sending to the server.

hnh
  • 13,957
  • 6
  • 30
  • 40
  • Thanks for your help! The sample code you provided is this a SOAP call? Why is XML used? – Mittchel Feb 28 '14 at 06:58
  • 1
    This is a WebDAV call and WebDAV uses XML for all the metadata operations. Googling I found this which seems to be an OK introduction: http://www.cs.unibo.it/~fabio/webdav/WebDAV.pdf – hnh Feb 28 '14 at 10:22
  • Hi Mitchel, the server url always is https://p02-caldav.icloud.com ? could it be p03, p04, p05.... ? – kairen Jul 17 '15 at 07:55
  • 2
    Could be any pXY. You start out with just caldav.icloud.com, and then you need to periodically check the home set URL in case a user gets moved to a different server. – hnh Jul 17 '15 at 07:58