Anyone successfully used Calendar.Events.patch() ?

714 views
Skip to first unread message

Jean-Luc Vanhulst

unread,
Dec 13, 2020, 7:45:04 PM12/13/20
to google-apps-sc...@googlegroups.com
I am trying to automatically add a person to an (Existing!) event on a Calendar AND make sure they get the notification.
I can use Event.addGuest without a problem and I'm able to use Calendar.Events.update( ) which is also an Api 3 Calendar function.

But I'm unable to get this to work:
Calendar.Events.patch(eventObject,calId, eId,{
    sendNotifications: true
  });

Anyone ever used the Script version of patch() - or solved the notification problem another way?

Thanks!

Jean-Luc Vanhulst

unread,
Dec 13, 2020, 7:54:40 PM12/13/20
to google-apps-sc...@googlegroups.com
Oh just to confirm I'm able to 'test' this here https://developers.google.com/calendar/v3/reference/events/patch and get a 200 ok

I just don't feel like adding the whole http version call hassle if I don't have to.
So I'm really just looking for a working script implementation. It's amazing how sparse the docs /examples are for some of these :)

Alan Wells

unread,
Dec 13, 2020, 8:02:55 PM12/13/20
to Google Apps Script Community
The advanced Calendar service must be turned on, and the API enabled in the associated Cloud Platform project.

The syntax is:
Calendar.Events.patch(resource, calendarId, eventId, optionalArgs)

The documentation is at:

The first parameter is for the resource.
Please show your resource object.

The resource is described at:

Jean-Luc Vanhulst

unread,
Dec 13, 2020, 8:51:24 PM12/13/20
to google-apps-sc...@googlegroups.com
It’s a working event object. Not null 

--


You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/069d7a70-2f28-4e3b-acf6-9304c18df4dfn%40googlegroups.com.


--

Alan Wells

unread,
Dec 13, 2020, 8:59:39 PM12/13/20
to Google Apps Script Community
I'm using it in my code to send invitations.

Jean-Luc Vanhulst

unread,
Dec 13, 2020, 9:05:53 PM12/13/20
to google-apps-sc...@googlegroups.com
What do you have in optional Args? Are you sending to a primary calendar?

--


You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.


Alan Wells

unread,
Dec 13, 2020, 9:15:31 PM12/13/20
to Google Apps Script Community
args = { sendUpdates: "all" };

Jean-Luc Vanhulst

unread,
Dec 14, 2020, 11:12:06 AM12/14/20
to google-apps-sc...@googlegroups.com
  Calendar.Events.patch(eventObject,calId, eId,{
     sendUpdates: "all"
  });

GoogleJsonResponseException: API call to calendar.events.patch failed with error: Request contains an invalid argument.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Adam Morris

unread,
Dec 14, 2020, 7:16:55 PM12/14/20
to google-apps-sc...@googlegroups.com
Try using the "try this API" to work, and make sure you set conferenceDataVersion to something

Jean-Luc Vanhulst

unread,
Dec 14, 2020, 9:11:50 PM12/14/20
to google-apps-sc...@googlegroups.com

cbmserv...@gmail.com

unread,
Dec 14, 2020, 9:17:00 PM12/14/20
to google-apps-sc...@googlegroups.com

Notifications of Calendar events is a weak area. Even under manual changes, if you select send updates or not, it still sends updates to all.

 

Under programmatical deletion of an event, there are no notifications sent to the invited guests. I had opened a ticket on that which was accepted by Google but no fix yet. Feel free to star it:

 

https://issuetracker.google.com/issues/167800880

Jean-Luc Vanhulst

unread,
Dec 14, 2020, 9:23:08 PM12/14/20
to google-apps-sc...@googlegroups.com
Well - I'm on the other end - addGuest() has the same limitation UNLESS the event has 
sendUpdates : "all"  which is exactly what I'm trying to set with patch or update before doing addGuest()

Jean-Luc Vanhulst

unread,
Dec 14, 2020, 9:27:18 PM12/14/20
to google-apps-sc...@googlegroups.com
So when running the 'Try me option' all goes well:

image.png

Jean-Luc Vanhulst

unread,
Dec 14, 2020, 9:42:54 PM12/14/20
to google-apps-sc...@googlegroups.com
Ok - I found my solution! 

Not all event objects are created equally, apparently!

I had this:
  var eventObject = CalendarApp.getCalendarById(calId).getEventById(eId);
   // (Which returns a working event object that I can do something like addGuest() with successfully )
  Calendar.Events.patch(eventObject,calId, eId,{  sendUpdates: "all"  });

but only when I do 
 var eventObject = Calendar.Events.get(calId, eId);
  Calendar.Events.patch(eventObject,calId, eId,{  sendUpdates: "all"  });


The call to update or patch works!

cbmserv...@gmail.com

unread,
Dec 14, 2020, 9:51:01 PM12/14/20
to google-apps-sc...@googlegroups.com

Thanks for posting. I will try to do the same before deleting the event and see if it is sending notifications now or not.

 

From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> On Behalf Of Jean-Luc Vanhulst
Sent: December 14, 2020 6:43 PM
To: google-apps-sc...@googlegroups.com
Subject: Re: [Apps-Script] Re: Anyone successfully used Calendar.Events.patch() ?

 

Ok - I found my solution! 

 

Not all event objects are created equally, apparently!

 

I had this:

  var eventObject = CalendarApp.getCalendarById(calId).getEventById(eId);

   // (Which returns a working event object that I can do something like addGuest() with successfully )

  Calendar.Events.patch(eventObject,calId, eId,{  sendUpdates: "all"  });

 

but only when I do 

 var eventObject = Calendar.Events.get(calId, eId);

  Calendar.Events.patch(eventObject,calId, eId,{  sendUpdates: "all"  });

 

 

The call to update or patch works!

 

 

On Mon, Dec 14, 2020 at 9:27 PM Jean-Luc Vanhulst <jlvan...@write2market.com> wrote:

So when running the 'Try me option' all goes well:

 

image001.png

Jean-Luc Vanhulst

unread,
Dec 15, 2020, 8:50:58 AM12/15/20
to google-apps-sc...@googlegroups.com
I'm afraid that your bug report is still accurate. The CODE works - but the intended result (people receiving notifications) - does not seem to happen :(.

One step at a time.
I'm still surprised at the 'double versions' of the eventObject. 
I literally have to get two versions of it:

    var eventObject = Calendar.Events.get(calId, eId);
    Calendar.Events.patch(eventObject,calId, eId,{ sendUpdates: "all", sendNotifications :true });
    eventObject = CalendarApp.getCalendarById(calId).getEventById(eId);
    eventObject.addGuest( e.namedValues["Your (personal) Email"] );
    
I cannot run both Events.patch and Event.addGuest with the same object. I guess the difference between an Events and Event object :)

CBM Services

unread,
Dec 15, 2020, 10:26:27 AM12/15/20
to google-apps-sc...@googlegroups.com
I also looked at this further and there is no patch equivalent method available in the CalendarApp API interface. So I can not even try your solution.

The bug was opened back in September. Google is saying this is a feature request while I believe it is a bug. But either way, I hope it gets fixed soon.

From: Jean-Luc Vanhulst
Sent: ‎2020-‎12-‎15 5:50 AM
[The entire original message is not included.]

Jean-Luc Vanhulst

unread,
Dec 15, 2020, 12:52:41 PM12/15/20
to google-apps-sc...@googlegroups.com
Ok - so with my latest changes I have been able to receive an email invite! Moral of the story - do it all in one call ... So I removed the addGuest() call and instead add the person straight to the attendees[] and then call Events.update()

    eventObject.visibility ="public";
       eventObject.attendees.push( { "email": e.namedValues["Your (personal) Email"]} );
       Calendar.Events.update(eventObject,calId, eId,{ sendUpdates: "all", sendNotifications :true });

For your delete event usecase - I'm curious what would happen if you set attendees[] to [] and then do update() like above and THEN delete the event?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

cbmserv...@gmail.com

unread,
Dec 15, 2020, 4:00:55 PM12/15/20
to google-apps-sc...@googlegroups.com

In the calendarApp, there is no equivalent of update either. Also all attendees are referred to as guests, there is no distinction between the two.

 

I have tried to remove all guests from event before finally just deleting the whole event (you would think that if you are removed from an event, you would get an event cancellation notice), but no notification is sent out in that case either way.

 

I am surprised this passed testing the first time before making it available to the general population as obviously notifications are not working correctly (on delete). For invites, they do work fine.

Jean-Luc Vanhulst

unread,
Dec 15, 2020, 4:07:32 PM12/15/20
to google-apps-sc...@googlegroups.com
Ok - I just tested my hypothesis for you!
This actually does send a cancellation:

  var eventObject = Calendar.Events.get(calId, eId);
  eventObject.attendees =[];

  Calendar.Events.update(eventObject,calId, eId,{ sendUpdates: "all", sendNotifications :true }); 
image.png

Reply all
Reply to author
Forward
0 new messages