0

I am trying to add a calendar event to Plesk calendar using CalDAV my code is: I put request using curl to calendar URL, I got the exists events so the link not the problem, the problem is creat my code is:

$uid = "test-12345"; // setting this to an existing uid updates event, a new uid adds event
$url   =  'calender_url'.$uid.'.ics'; //http://mail.domain.com/calendars/DOMAIN/USER/Calendar/'.$uid.'.ics'
$userpwd = "user:password";
$description = 'My event description here';
$summary = 'My event title 1';
$tstart = '202006015T000000Z';
$tend = '20200616T000000Z';
$tstamp = gmdate("Ymd\THis\Z");

$body = "<<<__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";

$headers = array(
    'Content-Type: text/calendar; charset=utf-8',
    'If-None-Match: *',
    'Expect: ',
    'Content-Length: '.strlen($body),
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$exe = curl_exec($ch);
curl_close($ch);

and I got next error

This resource only supports valid iCalendar 2.0 data. Parse error: This parser only supports VCARD and VCALENDAR files

any advice? thanks in advance.

Matis
  • 611
  • 2
  • 11
  • 27
Roufail
  • 551
  • 1
  • 8
  • 23
  • The iCalendar data seems fine, but I suspect problem with newlines, maybe try adding `\r\n` to the end of each line? Similarly to sth like [this](https://stackoverflow.com/a/21403564/4107107) – Matis May 05 '20 at 07:14
  • Please provide the actual request that does get sent over. – Arnaud Quillaud May 05 '20 at 17:15

2 Answers2

0

You should replace

"<<<__EOD

with

<<<__EOD

and

__EOD";

with

__EOD;

0

PHP_EOL and TRIM() help me:

$calendarData = "
BEGIN:VCALENDAR".PHP_EOL."
VERSION:2.0".PHP_EOL."
BEGIN:VEVENT".PHP_EOL."
DTSTAMP:$tstamp".PHP_EOL."
DTSTART:$tstart".PHP_EOL."
DTEND:$tend".PHP_EOL."
UID:$uid".PHP_EOL."
DESCRIPTION:$description".PHP_EOL."
LOCATION:Office".PHP_EOL."
SUMMARY:$summary".PHP_EOL."
END:VEVENT".PHP_EOL."
END:VCALENDAR
";
$calendarData = trim($calendarData);

and watch carefully that the beginning of each line starts with a parameter and not a space or indentation. And.. now.. we can use (example to use in APP)

$etag = $this->calDavBackEnd->createCalendarObject($calendarId, $url, $calendarData);