4

I am trying to patch an existing event with new start and end date using the Google API Explorer

So my event at the moment looks like this

{
 "kind": "calendar#event",
 "etag": "\"2912997881756000\"",
 "id": "3fpkrr85sdfdgsdfsdsdflgn7vk74qhiv2o",
 "status": "confirmed",
 "htmlLink": "https://www.google.com/calendar/event?eid=M2Zwa3JsdfsdfyODVudWZobGduN3ZrNzRxaGl2Mm8gZHlsbsdfsdfi5pb19xNjUwcWRhcnYyam9vYWYzcTdudmhpc2ZvNEBn",
 "created": "2016-02-26T14:32:33.000Z",
 "updated": "2016-02-26T15:02:20.878Z",
 "summary": "aaaa",
 "creator": {
  "email": "xxxx@yyy.com",
  "displayName": "name"
 },
 "organizer": {
  "email": "xxxxxx@group.calendar.google.com",
  "displayName": "Display",
  "self": true
 },
 "start": {
  "date": "2016-02-26"
 },
 "end": {
  "date": "2016-03-02"
 },
 "iCalUID": "3fpkrr85nufasdfsdfsadfasdfhlgn7vk74qhiv2o@google.com",
 "sequence": 2,

 "reminders": {
  "useDefault": true
 }
}

And the request I am making from the Google API Explorer is something like this

PATCH https://www.googleapis.com/calendar/v3/calendars/ddfdfdfdfdf%40group.calendar.google.com/events/3fpkrr85nufhlgn7sdfsafdfdsghgffdhvk74qhiv2o?fields=start&key={YOUR_API_KEY}

{
 "start": {
  "dateTime": "2016-02-16T12:00:00+01:00"
 },
 "end": {
  "dateTime": "2016-02-18T13:00:00+01:00"
 }
}

But I always get the following error

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid start time."
   }
  ],
  "code": 400,
  "message": "Invalid start time."
 }
}

I am guessing this is happening because the event is an All Day event which means start is a Date field and I am sending DateTime but this is exactly what I want to do. Can't I just simply change the type of start and end from Date to DateTime?

UPDATE

Here is the php code for the path request

$client = $this->container->get('google.calendar.client');
                $client->setAccessToken($this->auth()->getIdentity()->getGoogleAccessToken());
                $service = new \Google_Service_Calendar($client);
                $event = new \Google_Service_Calendar_Event($eventData);
                $event = $service->events->patch($this->auth()->getIdentity()->getGoogleCalendarId(), $item->getGoogleId(), $event);
                $item->setGoogleId($event->getId());
                $this->getItemRepo()->save($item);
Optimus
  • 1,703
  • 4
  • 22
  • 41

2 Answers2

12

There seems to be a problem with leftover dates. Setting dates explicitly to null works:

{
 "start": {
  "dateTime": "2016-02-16T12:00:00+01:00",
  "date": null
 },
 "end": {
  "dateTime": "2016-02-18T13:00:00+01:00",
  "date": null
 }
}
luc
  • 3,642
  • 1
  • 18
  • 21
  • thanks for the reply. It seems like it's working from API explorer but I still get the same error when I do it via PHP SDK. (Screen shot of the data I am sending is here http://grab.by/Oro2 ) – Optimus Feb 26 '16 at 21:25
  • Are you using patch in there too? It looks like a full event from the screenshot. Can you try to capture the network request? – luc Feb 27 '16 at 10:25
  • 1
    Why are you not calling update if you are passing in the entire event? Anyways, could you instead get the network requests? – luc Feb 27 '16 at 20:04
  • 2
    using `update` instead of `patch` solved the problem! Thank you very much. – Optimus Feb 27 '16 at 21:27
2

I know it is an old thread but I just got the same error in the PHP SDK and thus a short information: In the PHP SDK there is a null Value Constant in the Goole_Model Class: Google_Model::NULL_VALUE. If you don't use this all fields set to "normal" null are just stripped out and will never be sent to the Google API and thus the patch request failes.