Using curl to update CalDAV calendar color

Been a while since I’ve posted. Haven’t done anything that isn’t already documented somewhere in a long time. But, I’m back. I’m a big proponent of owning your own data and self-hosting where possible. I self-host my calendars on a CalDAV server at my house (with public IPs). But most if not all clients assume you’re using Google Calendar at this point or Microsoft’s equivalent. So, they tend to miss features. In this case, they were missing the ability to set a calendar’s color.

I run a Davical instance as my server. For my laptop, I use Thunderbird and its calendar. On my Android phone, I use Google Calendar as the client. Since it doesn’t support CalDAV, I sync it with DAVx5. The Davical webserver is available on a public IP protected with mTLS (client certificate authentication) and a username/password combination. The certificate blocks anyone that isn’t me from accessing the web service at all.

The problem I was experiencing was that my phone would use the same color for all my calendars (I have 5 distinct calendars) which made it hard to see what each event was for. Thunderbird had colors but they appeared to be locally derived and managed. Neither Google Calendar nor DAVx5 have the ability to set the color of a CalDAV calendar. The question was, can I set the color of the calendar in the calendar itself and have that propegate to my clients. I knew it was possible because Apple products can do it. But can my stack do it…

There is an open issue in Davical where someone asks to have this ability in the Davical server UI. Which would be a decent place to put it. People can access the UI and set the colors and have them propegate… https://gitlab.com/davical-project/davical/-/issues/131. But it hasn’t been touched in years. After reading the Thunderbird code for caldav, it does look for the calendar-color property, but doesn’t set it. DAVx5 has the ability to let apps manage the color and can pass colors through. Maybe this will be a feature there at some point. And I doubt Google Calendar is going to do anything.

So I need a way to set it outside of my clients… CURL it is. Curl is a command line web interface and I can use it to set the color property using XML and PROPPATCH (https://stackoverflow.com/questions/30861503/caldav-event-coloring-existing-alternatives)

avarese@savaresefw16:~$ curl -X PROPPATCH 'https://services.scottsavarese.com/davical/caldav.php/savarese/kids' -H 'Authorization: Basic abc123' --data '<propertyupdate xmlns="DAV:">
  <set>                                                 
    <prop>
      <calendar-color xmlns="http://apple.com/ns/ical/">#d63a47</calendar-color>
    </prop>
  </set>                 
</propertyupdate>' 

Notice the namespace is apple.com for the calendar color option. This is an Apple property which explains why it works on Apple products well. But the code does result in a 200 and is successfully saved. We can query for it as well:

savarese@savaresefw16:~$ curl -X PROPFIND 'https://services.scottsavarese.com/davical/caldav.php/savarese/calendar' -H 'Authorization: Basic abc123' --data '<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" xmlns:A="http://apple.com/ns/ical/">
  <d:prop>
     <d:displayname />                                                          
     <cs:getctag />
     <A:calendar-color />
  </d:prop>                                                                                                                                                   </d:propfind>'

Again, notice the namespace being defined in the XML.

Once done, I did have to drop the calendar from Thunderbird and recreate it (which is fine since all data is stored on the server and not my laptop. (Note: gotta make sure my backups are good). For DAVx5 I had to refresh and resync my calendars. I did notice that the color now appears as a bar on the calendar in the app so I see it there. Then I had Google Calendar resync and it picks up the color. If it doesn’t you can turn the calendar off in DAVx5 sync a few times with Google Calendar and then turn it back on and the color should propegate nicely.