Reputation: 926
I'm trying to update an event in Google Calendar using JavaScript and just cannot seem to achieve a simple update of specific variables I specify. The code below is what I've tried so far along with other similar combinations:
var event = {};
// Example showing a change in the location
event = {"location": "New Address"};
var request = gapi.client.calendar.events.update({
'calendarId': 'primary',
'eventId': booking.eventCalendarId, // Event ID stored in database
'resource': event
});
request.execute(function (event) {
console.log(event);
});
Regardless of the API Reference I've attempted to follow, I've tried getting the event itself and passing that reference to attempt to update specific variables. However, using the closest working sample code above I've noticed the console advises that I'm missing the start and end dates as minimum parameters. I obviously can add this to the 'event' object, yet this isn't effective as I only wish to update the fields I specify. The only other option is simply deleting the event and creating a new one - there must be a simpler way or there is something I have completely missed out entirely.
Upvotes: 4
Views: 6086
Reputation: 926
Managed to fix this problem myself, if anyone happens to experience the same issue. The correct format is to use 'PATCH' versus 'UPDATE', which allows for specific fields to be updated rather than having to set up the minimum range of fields required for 'UPDATE'.
This is the correct code I found that fixed the problem as an example, including a slight initial edit by getting the event first of all:
var event = gapi.client.calendar.events.get({"calendarId": 'primary', "eventId": booking.eventCalendarId});
// Example showing a change in the location
event.location = "New Address";
var request = gapi.client.calendar.events.patch({
'calendarId': 'primary',
'eventId': booking.eventCalendarId,
'resource': event
});
request.execute(function (event) {
console.log(event);
});
Upvotes: 15