How to self-host our Contacts list on NextCloud

; Date: Sat Feb 24 2024

Tags: Self Hosting »»»» Personal Privacy

Smart phones conveniently hold what used to be a paper phone and address book. The Contacts app stores names, addresses, phone numbers, and other data about our people or business contacts. NextCloud is a comprehensive open-source solution for sharing our data, including our contacts list, between multiple devices.

Our contacts list is personal identification information. It lists the people and businesses we interact with, remembering for us their names, phone numbers, e-mail addresses, and more.

Since this has potential for misuse, we must be careful with this information. I went over this in detail in Why avoid sharing smart phone Contacts using iCloud/Google/etc

Desiring a free flow of contacts between Android, iOS, CARDDAV (NextCloud), and desktop computers

What's desired is easy updates to my contacts list on any device, whether it's an iOS or Android smart phone, a desktop computer, or laptop computer. The contacts list in NextCloud will be used as the hub, with apps on each device synchronizing contacts to/from NextCloud.

The CARDDAV protocol is key. This is an open standard, as is the data format for contact information.

In order for me to own my data, I must be able to easily transfer contace data between devices as desired, when desired. The same holds true for other kinds of data, such as calendars.

Storing a Contacts list on NextCloud

First, make sure that the Contacts application is enabled in your NextCloud instance. It is in the Featured apps list, and is maintained by the NextCloud team.

Next, use one of the methods described in How to import or export contacts data on Android and iPhone (iOS) devices for exporting a Contacts list from your phone or other service.

You should export contacts in vCard format. The file extension will be .vcf.

The contacts list can be on your computer hard disk, or in your NextCloud account.

While logged-in to NextCloud, go to the Contacts tab. At the bottom of the left-hand navigation pane, you'll find Contacts Settings.

In the pop-up window, scroll down to find a button labeled Import Contacts.

Click on that, and you're given a choice "Select local file" or "Import from files". With the first you'll import from a file on your computer, with the second it's importing from a file in NextCloud.

For either, a file selection window appears. Navigate to and select your contact file.

After a short time, the contacts list will be imported.

Exporting a contacts list from NextCloud

Looking around the Contacts tab of the NextCloud instance, there isn't an obvious mechanism for exporting the entire contacts list as a .vcf file.

After some hunting, one can easily export a specific contact. While viewing the contact entry, in the upper-right corner there is a ... button. On that menu is a Download choice which exports as a .vcf file in your Downloads directory.

In (help.nextcloud.com) help.nextcloud.com, there is a discussion of this issue. The feature existed in OwnCloud but was removed in NextCloud. That NextCloud can export individual contacts as .vcf it's clear that it could easily export the entire contacts list that way.

The discussion includes some URLs to query, and a link to (codeberg.org) an open source tool for backing up NextCloud contacts lists. One can also use the Cadaver tool (this manipulates WEBDAV stores).

Using Cadaver to retrieve a Contacts list from NextCloud

(github.com) Cadaver is useful for interacting with WEBDAV. Contacts are accessed over WEBDAV as CARDDAV, and therefore Cadaver can access the contacts stored in NextCloud.

On Ubuntu, Cadaver is installed as so:

$ sudo apt-get install cadaver

On macOS, it can be installed as so:

# MacPorts
$ sudo port install cadaver
# HomeBrew
$ brew install cadaver

Once installed, the contacts list can be accessed this way:

$ cadaver https://cloud.DOMAIN/remote.php/dav/addressbooks/users/USER-NAME/contacts/\?export
Authentication required for Nextcloud on server `cloud.DOMAIN':
Username: USER-NAME
Password: 
dav:/remote.php/dav/addressbooks/users/USER-NAME/contacts/> ls
Listing collection `/remote.php/dav/addressbooks/users/USER-NAME/contacts/': succeeded.
        01C84393-6267-42CA-8A3D-44D6BB58C6FF.vcf        248  Feb 25 12:11
        02C3B452-8C6E-42BC-8993-A9EF17F505D8.vcf        261  Feb 25 12:11
        0430CDA4-DE23-4287-8E85-223909DA856B.vcf      24571  Feb 25 12:11
        050EFA57-BA72-47E9-8165-E8BF9C5947EE.vcf        360  Feb 25 12:11

If you've downloaded an individual contact via the NextCloud user interface, you'll recognize this file name format. The Username and Password to use are what you login with at the NextCloud web user interface.

Cadaver brings you into a command-line environment that will be familiar to any user of FTP or SFTP tools from the last 50 years.

dav:/remote.php/dav/addressbooks/users/USER-NAME/contacts/>

This is a command-line prompt. The following commands are available:

dav:/remote.php/dav/addressbooks/users/USER-NAME/contacts/> help
Available commands: 
 ls         cd         pwd        put        get        mget       mput       
 edit       less       mkcol      cat        delete     rmcol      copy       
 move       lock       unlock     discover   steal      showlocks  version    
 checkin    checkout   uncheckout history    label      propnames  chexec     
 propget    propdel    propset    search     set        open       close      
 echo       quit       unset      lcd        lls        lpwd       logout     
 help       describe   about      
Aliases: rm=delete, mkdir=mkcol, mv=move, cp=copy, more=less, quit=exit=bye

It turns out that typing mget * downloads everything in the current "directory" of the CARDDAV service. You might end up with the following in your current working directory:

$ ls
01C84393-6267-42CA-8A3D-44D6BB58C6FF.vcf  877856A7-813E-4B6A-AF0F-B7142A88CF09.vcf
...

What you then do with the individual files is up to you.

Synchronizing to the NextCloud-hosted Contacts list from iOS devices

The Contacts app on iOS has a native ability to connect to any CARDDAV service, including NextCloud. The (docs.nextcloud.com) online NextCloud documentation has instructions for connecting to both the Contacts and Calendar service in NextCloud.

In the iOS Settings app, go to Contacts, and tap on Accounts. This shows you the current list of account subscriptions. Add a new account.

For the Server choice, enter the domain name of your NextCloud instance. Then enter your user name and password. The contacts app will take care of the rest, and set up to receive contacts from the server. I haven't yet tried subscribing to a NextCloud calendar, but it should be as simple.

You must use an HTTPS URL, rather than HTTP, meaning your NextCloud instance must have an SSL certificate. The simplest choice for that is Lets Encrypt.

Subscribing to the NextCloud-hosted Contacts list from Android devices

Surprisingly the Android Contacts application cannot innately connect to a CARDDAV service. It can connect to the Contacts stored in a Google Account. But, our goal is connecting the contacts on a CARDDAV service like NextCloud.

Surprisingly, the NextCloud app for Android does not handle synchronizing Contacts.

The (docs.nextcloud.com) online NextCloud documentation discusses using DAVx5 and/or Open Tasks to synchronize contacts and/or calendars to/from NextCloud. This application also supports a long list of other services. But, the $6.99 price is offputting.

ContactSync - CardDAV and more makes similar claims to DAVx5, and at the lower price of $3.99 is a little less offputting.

AutoSync is a general file synchronizing application which looks to be very powerful. With it you can synchronize folder(s) on your Android device with folder(s) on a cloud service, including NextCloud. SyncThing offers similar features. The issue is they transfer files back and forth, which does not solve the issue of auto-syncing Android contacts with a CARDDAV server like NextCloud.

Using the search phrases "contacts app for android which synchronizes with carddav", or "android contacts app subscribes carddav", results in many suggestions to use DAVx5. I hoped to find a replacement Contacts app that directly interacted with a CARDDAV service. Instead, the story seems to be using DAVx5 with the standard Contacts app.

Between DAVx5 and ContactSync, DAVx5 is the more flexible solution. ContactSync only deals with Contacts, while DAVx5 deals with CalDAV (Calendars) and Tasks (using VTODO) in addition to contacts (CARDDAV).

Synchronizing NextCloud Contacts with Thunderbird

Connecting to the contacts on NextCloud is trivially easy with Thunderbird.

In the Address Book area of Thunderbird, there is a choice for New Address Book. This includes a dropdown menu where one choice is to create a new CARDDAV address book.

In the popup window you enter the https://cloud.DOMAIN URL for your NextCloud instance, as well as your user name. Upon clicking Continue you'll be asked for a password. It then goes through automated discovery of the service parameters, and automatically downloads the contacts into Thunderbird.

Synchronizing NextCloud Contacts with GNOME Contacts

Connecting to the contacts on NextCloud is easy with with GNOME Contacts. Not trivially easy, but still easy.

I am running Ubuntu on this laptop, and installing the application is this easy:

$ sudo apt-get install gnome-contacts

Out of the box GNOME Contacts only supports a local address book. But in the GNOME Settings application, there is a section for Online Accounts.

In the Settings application, NextCloud is on the list of providers. Start by clicking on NextCloud, then entering the username/password and domain name of your NextCloud instance. The account will appear in the Online Accounts section of your Settings application.

In GNOME Contacts there is a button with three horizontal stripes. This has a menu, and one choice is about changing the address book to an Online Account.

As soon as you change to Oneline Accounts, the Contacts application shows the contacts stored on NextCloud.

Contacts added on other clients, that are successfully synchronized to NextCloud, do make it into the GNOME Contacts application. However, it seems that a contact added in GNOME Contacts does not synchronize to NextCloud. For contacts synchronized from NextCloud, a change made using GNOME Contacts is synchronized back to NextCloud.

Contacts data trapped in corporate silos

The desired goal expressed earlier is a free flow of contacts data between mobile devices, NextCloud, and desktop applications. But, the reality is very different from that rosy desire.

The combination of Thunderbird and NextCloud demonstrates what we want. I was easily able to add a Thunderbird address book to the CARDDAV service on NextCloud. I could then edit a contact on either end, and have the updated contact appear almost immediately on the other.

The combination of GNOME Contacts and NextCloud works similarly. I was able to easily add the NextCloud contacts to GNOME Contacts. Editing a contact in one immediately is reflected in the other. But it does not quickly respond to a contact edited in Thunderbird, even though that is immediately reflected in NextCloud.

Solving issues with synchronizing contacts with iPhone (iOS)

Synchronizing contacts with my iPhone was difficult to set up. The instructions, as described earlier, are very simple. Just add an account for NextCloud and (supposedly) contacts will start synchronizing between NextCloud and iOS.

In reality the contacts did not synchronize between them. I'd make a change on one, wait a long time, and the change would never show up. The reason to wait a long time is a setting on iOS for when to synchronize contacts. There is a Fetch mode which can be "automatic" or waiting a certain amount of time between fetches. There is also a Push mode that's presumably nearly instantaneous. Depending on those modes there could be a pause before synchronization.

No amount of waiting made a difference.

The solution was very simple, but not documented.

Namely, when the contacts list is imported into NextCloud, the imported contacts are added to the "Not Grouped" group. Contacts in this group are not synchronized out to other clients by NextCloud.

Since every contact was in the group named "not grouped", none of the changes I'd made were synchronized to the iPhone.

To test, I added a couple of the contacts to groups, and modified them. I also added a couple new made-up contacts. These which were in groups synchronized, but not always quickly, and not always reliably.

Summary

In one evening I tried all the iPhone apps listed above. That was hours of frustration with the difficulty in extricating the Contacts list from my iPhone. Immediately afterward I tried the same task on my Android phone. The ease with which that happened, and the "of course you deserve to export your data" design of the Android contacts application, was a breath of fresh air.

I found myself pondering: Why does Apple make it so hard to export the Contacts list? What does Apple hope to gain?

Any service, whether it's Apple, Google, Twitter, Facebook, etc, is storing our data. By what right do these service providers have to prevent us from using our data as we wish? All such applications should embody the concept that, of course the data is yours, and make it trivially easy to export or import data as desired.

Why do both Apple and Google (who control the smart phone market) make it hard to easily transfer contacts (or other data) among any compatible 3rd party service? It's about control. Both have their own services (iCloud or Google account services), and it serves both companies to have their customer data trapped in those services.

A rich ecosystem of compatible CARDDAV, CALDAV, etc services threatens both Apple's and Google's ability to lock customers into their the iOS or Android ecosystem. We, the customers, should be free to use any compatible service. Instead, the design of both iOS and Android prevent that from happening. Instead of a free flow of data, like contacts lists, between any combination of desktop, laptop, smart phone, or tablet computer device, we are limited by design decisions of the iOS and Android product teams.

About the Author(s)

(davidherron.com) David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind power, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from electronic mail systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.