Search code examples
google-calendar-api

Google calendar watch doesn't send notifications after the initial sync notification


I have set up a watch on a google calendar.


            WatchParamsModel watchParamsModel = new WatchParamsModel
            {
                TimeToLive = "2592000000", // 30 days is the max that google will allow
            };
            WatchRequest requestCode = new WatchRequest
            {
                ID = "abc_" + providerID + "_" + calendarID + "_" + DateTimeOffset.Now.ToUnixTimeSeconds(),
                Type = "web_hook",
                Address = address,
                Params = watchParamsModel,
                Token = "token",
            };

            string requestData = JsonConvert.SerializeObject(requestCode);

            string requestUrl = $"https://www.googleapis.com/calendar/v3/calendars/{calendarID}/events/watch?eventTypes=default";

            WatchResponse response = this.CreateAndExecuteHttpRequest<WatchResponse>(requestUrl, WebRequestMethods.Http.Post, requestData);
            return response;

I get a 200 response with all the expected information

{  
"kind": "api#channel",  
"id": "watchid",  
"resourceId": "abc",  
"resourceUri": "https://www.googleapis.com/calendar/v3/calendars/{calURI}/events?alt=json&eventTypes=default",  
"token": "token",  
"expiration": "1711044580000" 
} 

and the sync notification:

Method: POST, 
RequestUri: 'my endpoint', 
Version: 1.1, 
Content: System.Net.Http.StreamContent, 
Headers:  {    
Accept: */*  Accept-Encoding: gzip  
Host: my host  
User-Agent: APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)  
X-Forwarded-For: 123  
X-Forwarded-Proto: https  
X-Forwarded-Port: 443  
X-Amzn-Trace-Id: Root=abc  
CF-RAY: abc 
CF-Visitor: {"scheme":"https"}  
X-Goog-Channel-ID: channelId (same as above)
X-Goog-Channel-Expiration: Thu, 21 Mar 2024 22:47:00 GMT  
X-Goog-Resource-State: sync  
X-Goog-Message-Number: 1  
X-Goog-Resource-ID: resourceId (same as above)
X-Goog-Resource-URI: https://www.googleapis.com/calendar/v3/calendars/{calURI}/events?alt=json&eventTypes=default  
X-Goog-Channel-Token: token (same as above)  
CF-Connecting-IP: 74.125.212.171  
CDN-Loop: cloudflare  
True-Client-IP: 74.125.212.171  
CF-IPCountry: US
}

Within the endpoint first thing that gets done is that I log the any incoming request. However, when checking the logs I don't see that anything comes in when I create/edit/delete an event within the associated google calendar after creating the watch. I checked our firewall and nothing coming from google is getting blocked. I can see the sync call coming through and our 200 response. I am not seeing any calls being blocked by the firewall or otherwise for when an event is edited. Why am I not getting any calls to the endpoint after the initial sync call?


Solution

  • Removing the eventTypes=default will most likely fix the missing push notifications, as Alexey shared in a comment. Google sent out a notice on February 7th that eventTypes=default should be supported, but I have been unable to get it working as of March 11th. Removing the paramter restored the push notification functionality back to a working state.