Google changed something in their Calendar API around late May 2024 and now my Apps Script breaks when trying to modify events that come from Gmail.
I have a script that changes event colors for both regular calendar events and the ones Gmail creates automatically. The regular events still work fine, but Gmail-created events throw errors every time I try to update them.
From what I read, Google now limits what you can change on Gmail events. You can only modify reminders, colorId, visibility, status, and extendedProperties. Even though colorId is supposed to be allowed, my script still fails.
I keep getting “Bad Request” errors when the script tries to update Gmail-created events, but regular events work perfectly. Has anyone else run into this problem?
Hit this same issue two months ago and wasted hours debugging it. The colorId property isn’t the problem - it’s how you’re handling the event object before sending it back to the API. Gmail events come with extra read-only properties that break the update when you include them in the request. I fixed it by creating a clean event object with just the properties I wanted to change, instead of updating the original object from the list response. Try creating a new object like {colorId: “10”} and pass that to the update method instead of your modified currentEvent object. The API docs mention this but it’s buried in fine print. Been working perfectly since I switched to this approach.
Your Google Apps Script is failing to update the color of events created by Gmail in Google Calendar. This is due to limitations in the Google Calendar API regarding modification of Gmail-created events. While the colorId property should be modifiable, the API throws “Bad Request” errors when attempting updates on these specific events. The root cause is that the original event object retrieved from Calendar.Events.list() contains read-only properties that conflict with the update process.
Understanding the “Why” (The Root Cause):
Gmail-created calendar events have different permission levels and contain additional read-only metadata compared to manually created events. When you retrieve a Gmail event using Calendar.Events.list(), this metadata is included in the currentEvent object. Attempting to update the event using this object, even with only intended changes, fails because the API rejects the presence of these extra, unmodifiable fields. The API’s validation process flags the entire request as invalid due to this inclusion.
Step-by-Step Guide:
Rebuild the Update Payload: Instead of modifying the existing event object retrieved from Calendar.Events.list(), create a new object containing only the properties you wish to change. This avoids including the read-only properties that cause the API errors. For this specific case, you only need the colorId.
Implement the Corrected Update: Modify your Apps Script to use this new approach. Replace your existing Calendar.Events.update() call with the following:
var calendarEvents = Calendar.Events.list(myCalendarId, searchOptions)["items"];
for (var j = 0; j < calendarEvents.length; j++) {
var currentEvent = calendarEvents[j];
try {
Calendar.Events.update(
{ colorId: "10" }, // New object with ONLY the property to change
myCalendarId,
currentEvent.id);
} catch (error) {
Logger.log('Update failed with error: ' + error);
}
}
Verify Your Solution: Run your Apps Script again. The updated code should successfully change the colorId property of both manually created and Gmail-created events without throwing “Bad Request” errors. If errors persist, ensure you have the necessary API permissions and that myCalendarId is correctly set.
Common Pitfalls & What to Check Next:
Incorrect myCalendarId: Double-check that myCalendarId accurately reflects the ID of the calendar you are attempting to modify. An incorrect ID will lead to update failures.
Insufficient API Permissions: Verify that your Apps Script has the necessary authorization scopes to modify events in Google Calendar. The required scope is likely https://www.googleapis.com/auth/calendar.events.
Rate Limiting: If you are processing many events, the Google Calendar API might be rate-limiting your requests. Implement exponential backoff and retry logic to handle temporary failures. This includes adding delays between API calls to avoid exceeding request quotas.
Event Visibility: Confirm that the events you’re targeting are not set to private. Updating private events may be more restricted.
Latenode as an Alternative: If you anticipate continuing difficulties integrating directly with Google’s APIs, consider the use of Latenode as a third party platform. Latenode handles these API nuances internally and can provide more robust error handling and a simpler way to manage your calendar automation.
Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!
Google started enforcing stricter validation on Gmail events recently. When you grab an event with Calendar.Events.list(), it pulls in read-only metadata fields that Gmail events have. If you try to pass all that data back in an update request, you’ll hit a Bad Request error. I ran into this exact issue after the May update. Fixed it by building the update payload from scratch instead of modifying the whole event object. Just grab the event ID and send a minimal update with only the fields you’re changing. Here’s how to fix your code: Calendar.Events.update({colorId: "10"}, myCalendarId, currentEvent.id); This skips the validation problems since you’re only sending what’s needed. The API handles partial updates fine, so no need for the full event object. Works consistently for both regular and Gmail events since May.