caldavnextcloudsabredav

Creating a new calendar in Nextcloud/SabreDAV via CURL


I've created a demo Nextcloud build(the backend seems to be SabreDAV) and enabled the calendar app. Functions like PROPFIND are working via CURL, but I can't create a new calendar(not a calendar object).

The MKCALENDAR functions doesn't exist on the server, so I'm using MKCOL based on the RFC5689 spec like so:

<D:mkcol xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
 <D:set>
   <D:prop>
     <D:resourcetype>
       <D:collection/>
       <C:calendar/>
     </D:resourcetype>
     <D:displayname>New Event XYZ</D:displayname>
   </D:prop>
 </D:set>
</D:mkcol>

Here's the full command I'm running:

curl -v --user "admin:admin" -H "Content-Type: application/xml" -X MKCOL "https://try.nextcloud.com/ohth5ael/remote.php/dav/" -d '<?xml version="1.0" encoding="utf-8" ?><D:mkcol xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"><D:set><D:prop><D:resourcetype><D:collection/><C:calendar/></D:resourcetype><D:displayname>Lisas Events</D:displayname></D:prop></D:set></D:mkcol>'

And the error response:

<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\NotFound</s:exception>
  <s:message>Node with name 'root' could not be found</s:message>
</d:error>```

Solution

  • Turns out MKCALENDAR works but it was being rejected due to an incorrect request.

    The URL being sent needs to point to the calendar that's being created. It isn't derived from the "displayname" entry in the XML. So:

    curl -v --user "admin:admin" -H "Content-Type: application/xml" -X MKCALENDAR "https://try.nextcloud.com/ohth5ael/remote.php/dav/calendars/admin/newcal"
    

    Nothing is required in the body of the request, unless you want to tweak the calendar parameters(display name, color, etc).