lambdabaa / dav

WebDAV, CalDAV, and CardDAV client for nodejs and the browser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contacts from iCloud are filtered out

ide opened this issue · comments

I looked into using dav to interact with my iCloud contacts so that I could programmatically add contacts to my phone. One of the first things I ran into was that dav returns an empty list of address books because it filters out all address books missing a displayname field. When I remove that filter call, I get back all of my iCloud contacts.

I'm not familiar with DAV and don't know the right fix right now but maybe someone who has experience with DAV knows how to address this.

Code:

var dav = require('dav');
var util = require('util');

var xhr = new dav.transport.Basic(
  new dav.Credentials({
    username: 'xxx@gmail.com',
    password: 'hunter2',
  })
);

var client = new dav.Client(xhr);
client.createAccount({
  accountType: 'carddav',
  server: 'https://contacts.icloud.com',
  loadCollections: true,
  loadObjects: true,
}).then(account => {
  console.log(util.inspect(account.addressBooks, false, null));
}).catch(error => {
  console.error(error);
});

@ide How exactly did you get this working? Using your example code I simply receive an empty array.

IIRC the example code only reproduces the issue but it was from over a year ago.

So you didn't manage to use this library to retrieve your contacts?

From my original post it sounds like you could fork this library and get it working for this specific use case if that’s important. But I don’t think I used this library for my own project.

Thanks.

Tested with removing the filter and it still returns an empty list of addressBooks, so seems that it fails somewhere else too.

commented

This works for me with iCloud
`addressBooks = responses.filter(function (res) {

        //return typeof res.props.displayname === 'string';

        return res.props.resourcetype.includes('addressbook');

}`