Creating a new calendar via CURL

I’ve created a demo Nextcloud build(https://try.nextcloud.com/cie7oofe) 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 spec 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/cie7oofe/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>New Event XYZ</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>

Nextcloud version: 60min demo version on try.nextcloud.com

Steps to replicate it:

  1. Create demo server
  2. Install calendar app
  3. Run Curl command via terminal

(This is also cross posted on stackoverflow, in case someone wants to answer it there as well)

Figured it out.

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/cie7oofe/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).

2 Likes