Add calendar event to Nextcloud using curl

I am unsuccessfully trying to add an event to Nextcloud agenda (Nextcloud version 16), using cURL :

curl --user 'user:pass' -X PUT \
https://myNCserver/remote.php/dav/calendars/user/myCalendar /Myevents-Z2HOOON14VOH09RIACY3IL3W.ics \
-H "Content-Type: text/calendar ; charset=utf-8" --data @myEvent.ics

The content of the myEvent.ics file :

BEGIN:VCALENDAR
PRODID:-//My own caldav script
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
CREATED:20190606T094245
DTSTAMP:20190606T094245
LAST-MODIFIED:20190606T094245
UID:VYM30SH4VNJFV4CWAUC0V9
SUMMARY:Test added using cURL !
CLASS:PUBLIC
STATUS:CONFIRMED
DTSTART;TZID=Europe/Zurich:20190606T200000
DTEND;TZID=Europe/Zurich:20190606T210000
END:VEVENT
BEGIN:VTIMEZONE
TZID:Europe/Zurich
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
END:VCALENDAR

I’ve validated this content using https://icalendar.org/validator.html

The UID is randomly generated using :

cat /dev/urandom | tr -dc 'A-Z0-9' | fold -w 22 | head -n 1

And the same for the file / ressource name Myevents-Z2HOOON14VOH09RIACY3IL3W.ics

I receive the following answer from the server :

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\UnsupportedMediaType</s:exception>
  <s:message>This resource only supports valid iCalendar 2.0 data. Parse error: This parser only supports VCARD and VCALENDAR files</s:message>
</d:error>

I’ve tried to rename the .ics in .vcal , no luck.

Also I’ve looked into the Nextcloud log file, it contains a big json array, which does not provide more information than the error message returned, at least none that I can understand !

Found the solution : the -d myEvent.ics option of curl is not ok here, since it does not preserve the line feeds of the submitted data file.

Instead, one must use the --data-binary @myEvent.ics ! This option preserves the line feeds and then the Nextcloud server accept the request and creates the event in the calendar.

3 Likes