Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple iCloud access to contacts in uwp application

Tags:

c#

.net

icloud

uwp

I am trying to access my iCloud contacts in my UWP application. I know that I can access my Gmail Contacts through Google's People API and my Outlook contacts through Microsoft's Graph api OR Outook people api .

Does Apple provide an API (Rest or otherwise) that could be leveraged to fetch, update, add, delete contacts? If yes, is there a tutorial that walks through how to setup access iCloud api?

like image 688
Akshay Gaur Avatar asked Sep 19 '25 03:09

Akshay Gaur


1 Answers

So, if you just want to fetch the contacts (and in JSON format) my previous answer is probably the way to go. However, as I wanted to be able to perform CRUD operations on Apple account, a better way is to use the CARDDAV protocol that icloud/apple supports.

  1. Get the principle user using basic authentication (the password used in this basic authentication would have to be generated as an app password here) by firing a PROPFIND request at https://contacts.icloud.com with the request content:
<propfind
xmlns="DAV:">
<prop>
    <current-user-principal/>
</prop>
</propfind> 
  1. The previous step will let you retrieve a principle which will be of the format /1437425399/principal/. Now, you can fire a PROPFIND query the home-set for this user at the link https://contacts.icloud.com/1437425399/principal with the following request content:
<propfind
    xmlns="DAV:"
    xmlns:c="urn:ietf:params:xml:ns:carddav">
    <prop>
        <c:addressbook-home-set/>
    </prop>
</propfind>
  1. From the previous request, you will get the link to the homeset in the format https://p48-contacts.icloud.com:443/1437425399/carddavhome/. You can query where the vcards for the user exist using the following PROPFIND request at the home-set link:
<propfind
xmlns="DAV:">
<prop>
    <resourcetype/>
</prop>
</propfind>
  1. You will receive the place where all the cards are placed (eg. /1437425399/carddavhome/card/). Using a addressbook query, now you can initiate a REPORT request at the endpoint received in the previous link:
<c:addressbook-query
    xmlns="DAV:"
    xmlns:c="urn:ietf:params:xml:ns:carddav">
    <prop>
    </prop>
</c:addressbook-query>
  1. This will give you all the cards in the tag. You can then fetch multiple cards using a addressbook-multiget REPORT request:
<c:addressbook-multiget
    xmlns="DAV:"
    xmlns:c="urn:ietf:params:xml:ns:carddav">
    <prop>
        <getetag />
        <c:address-data />
    </prop>
    <href>/1437425399/carddavhome/card/somecard.vcf</href>
    <href>/1437425399/carddavhome/card/anothercard.vcf</href>
</c:addressbook-multiget>

For updating, creating and deleting cards, you can fire PUT requests at "/1437425399/carddavhome/card/cardtobemanipulated.vcf" endpoint using the basic authentication that we discussed earlier after setting the Content-Type as "text/vcard" and sending the VCard in the content for update and create requests.

like image 175
Akshay Gaur Avatar answered Sep 21 '25 18:09

Akshay Gaur