Search code examples
javascriptgoogle-calendar-api

Forbidden 403 when trying to update via Google Calendar API


Trying to update a calendar event, with Googles API. It's not working out for some reason... It's just telling me "forbidden", and I can't find anything on Googles error handling documentation that matches this error message.

A few important key points:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Forbidden"
   }
  ],
  "code": 403,
  "message": "Forbidden"
 }
}

The data I'm trying to send:

let data = {
    'start': {
        dateTime: event_data.start.dateTime //This data is correct and is formatted to rfc3339
    },
    'end': {
        'dateTime': new Date().toISOString()
    } 
};

return new Promise((resolve, reject) => {

    xhr.onreadystatechange = (e) => {
      if (xhr.readyState !== 4) {
        return;
      }

      if (xhr.status === 200) {
        resolve(JSON.parse(xhr.responseText));
      } else {
        console.warn('request_error');
      }
    };

    xhr.open('PUT', 'https://www.googleapis.com/calendar/v3/calendars/'+calendar_id+'/events/'+event_id);
    xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
    xhr.send(JSON.stringify(data));
});


Solution

  • Okay so the problem relies with updating rights for Google Workspace accounts itself. Allowing up to 48 hours for the changes to take effect is what was necessary here, at the time of writing the post I had only waited around 12-14 hours.

    Now that I've waited the up to 48 hours, it works without having to change anything with the code. I couldn't find where Google specifies how long these updates take, but it's consistent with other Google services as well that sometimes waiting up to 48 hours is actually necessary.

    To summarize:

    • The account running the authorization was given Super Admin rights in Google Workspace
    • Waiting up to 48 hours for the changes to propogate
    • The code above is correct and works as intended
    • The event I was trying to update was not an event owned by the authorized account, thus giving Super Admin rights would give it the right to ALL calendars in the Google Workspace organization.