title: Create calendar events in NextCloud using PHP
body: <p>I'm trying to create a calendar event in Nextcloud with PHP and cURL. After running the code from command line, I get the following error from Nextcloud 12:</p>
  
  <pre><code>PUT is not allowed on non-files.
  </code></pre>
  
  <p>Here is the full code I'm using following <a href="http://sabre.io/dav/building-a-caldav-client/#creating-a-calendar-object" rel="nofollow noreferrer">this guide</a></p>
  
  <pre><code>&lt;?php
  $url = 'https://cloud.org/remote.php/dav/calendars/mycalendars/activity/';
  $headers = array('Content-Type: text/calendar', 'charset=utf-8');
  $userpwd = 'gerald:123';
  $description = 'new event description';
  $summary = 'new event';
  $tstart = gmdate("Ymd\THis\Z", strtotime("-2 days"));
  $tend = gmdate("Ymd\THis\Z", strtotime("-2 days"));
  $tstamp = gmdate("Ymd\THis\Z");
  $uid = 'event-123';
  
  $body = &lt;&lt;&lt;__EOD
  BEGIN:VCALENDAR
  VERSION:2.0
  BEGIN:VEVENT
  DTSTAMP:$tstamp
  DTSTART:$tstart
  DTEND:$tend
  UID:$uid
  DESCRIPTION:$description
  LOCATION:Office
  SUMMARY:$summary
  END:VEVENT
  END:VCALENDAR
  __EOD;
  
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
  //curl_setopt($ch, CURLOPT_PUT, true);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
  
  //Execute the request.
  $response = curl_exec($ch);
  curl_close($ch);
  
  echo $response;
  ?&gt;
  </code></pre>
  
  <p>Does this mean that CalDAV in Nextcloud doesn't support PUT? So how do calendar applications like Thunderbird Lightning create events in Nextcloud?</p>
  
  <p>In the Nextcloud <a href="https://docs.nextcloud.com/server/12/developer_manual/client_apis/WebDAV/index.html" rel="nofollow noreferrer">WebDAV documentation</a> I can't find anything about CalDAV implementation.</p>