skip to Main Content

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("YmdTHisZ");

$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.

2

Answers


  1. You should replace

    "<<<__EOD

    with

    <<<__EOD

    and

    __EOD";

    with

    __EOD;

    Login or Signup to reply.
  2. 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);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search