google calendar api Error 400 - Invalid resource id value

Viewed 4030

I want to insert events in Google calendar through the API using a Symfony command (batch).

When I insert an event with an ID like "event01487", it throws me the following errors : "code": 400, "message": "Invalid resource id value."

This id is unique as no events have been inserted - it didn't even insert it once. The id seems to fit the Google requirements...

Do you have any idea why I got this ?

foreach($bookingsToSync as $booking){
     $event = new Google_Service_Calendar_Event();
     $event->setId($booking['id']);
     $event->setSummary($booking['title']);
     $event->setDescription($booking['description']);

     $start = new \Google_Service_Calendar_EventDateTime();
     $start->setDateTime($booking['startDate']->format(DateTime::ATOM));
     $event->setStart($start);
     $end = new \Google_Service_Calendar_EventDateTime();
     $end->setDateTime($booking['endDate']->format(DateTime::ATOM));
     $event->setEnd($end);

     $output->writeln($event->getId());

     $service->events->insert($calendarId, $event);
}
2 Answers

You should encode your id as base32

$encoded = bin2hex( $booking['id'] );

To Decode

$decoded = hex2bin( $encoded );
Related