Reputation: 35
I am trying to update calendar events from google apps script. I have the calendar ID, event ID, and objects I am trying to update as a variable:
var eventinfo = {
"calendarId": calID
"eventId": eventID,
"resource": {
"description": "1234"
}
};
//update the event description and location
var updater;
try {
updater = Calendar.Events.update(eventinfo);
Logger.log('Successfully updated event: ' + i);
} catch (e) {
Logger.log('Fetch threw an exception: ' + e);
}
I am getting this error:
Fetch threw an exception: Exception: Invalid number of arguments provided. Expected 3-5 only
Previously, I had attempted to invoke the update method this way .update(calID, eventID, eventinfo)
where event info was an object with just a description, but that was returning the error saying bad call.
I think I am missing something in my object argument.
Upvotes: 1
Views: 4254
Reputation: 27400
First of all, you forgot a comma in the definition of eventinfo
between the first and the second row.
However, I don't think your approach will work, because you don't
pass an event object
in the Calendar.Events.update()
function. The structure should be like that:
Calendar.Events.update(
event,
calendarId,
event.id
);
The following example updates the very first event in the future. In particular, it updates the title (summary), description and place but feel free modify that if you want:
function updateNextEvent() {
const calendarId = 'primary';
const now = new Date();
const events = Calendar.Events.list(calendarId, {
timeMin: now.toISOString(),
singleEvents: true,
orderBy: 'startTime',
maxResults: 1
});
var event = events.items[0]; //use your own event object here if you want
event.location = 'The Coffee Shop';
event.description = '1234';
event.summary = 'New event';
event = Calendar.Events.update(
event,
calendarId,
event.id
);
}
Of course, don't forget to switch on the Calendar API from Resources => Advanced Google services.
Upvotes: 3