Carddav and Apple’s implementation

Carddav and Apple’s implementation

An upgrade of my Synology NAS from a wheezy, underpowered (for any more than file sharing) DS215j to a shiny new DS923+ means I can start to use a lot more of the Synology apps rather than relying on docker images on raspberry pis etc, and all the hassle that brings with backing up and restoring docker containers.

Synology offer nice, fully featured calendar and contacts apps so I dived in. The calendar app was a breeze and synced with MacOS no problem at all (and android via Davx5). Job jobbed, all data on MY NAS, under my control and nicely backed up within the synology backup tools.

Then we come to the Synology Contacts app. Works great with Davx5, seamless. Awesome. However, could I get the damn thing to sync with Apple’s contacts app within MacOS. Browsing the various forums it seems it’s a well known issue and is down to Apple’s implementation of carddav in a slightly non-standard way. I have found a solution.

It appears that Synology creates several address books per user (private, team etc) and yet Apple’s implementation is expecting only one addressbook, hence it gets its knickers in a twist when it tries to sync. I found a post on the synology forum which seems to have done the trick. In a nutshell it involves manipulating the postgres database on the Synology to rename the addressbook for each user to ensure the addressbook starts with a ‘1’. This is then the first addressbook Apple’s app looks for and so should sync.

The steps are:

  1. In the web interface for synology contacts untick all address books for each account except ‘the main addressbook’
  2. Enable ssh access to the nas
  3. login in to the nas via ssh
  4. sudo psql -u postgres to access the databases
  5. \l to list the databases, you should see synocontacts
  6. \c synocontacts to connect to the contacts database
  7. \d to list the tables
  8. select * from addressbook; (the semi colon is important!) to show the contacts. Find the ID of the user that matches the carddav link in the web interface of synology contacts
  9. update addressbook set uri='carddav link' where id ='id of user'; and change the first digit of the carddav link to a 1
  10. \q to quit

On your mac, fire up the contacts app and add an account –

  1. Contacts/Add Account
  2. ‘Other contacts account’ and continue
  3. Type is Carddav
  4. Account type is Manual
  5. Username is the Synology NAS username
  6. Password is obvious
  7. Server link is <name or IP of synology NAS>/carddav/Username
  8. Click sign-in

Give it a few seconds and you should see your contacts piling in.