Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import iCloud contacts .NET (CardDAV)

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.

like image 739
Mittchel Avatar asked Jun 14 '13 08:06

Mittchel


1 Answers

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.

like image 177
hnh Avatar answered Sep 25 '22 11:09

hnh