Ref: https://developers.google.com/admin-sdk/alertcenter/reference/rest
The getSettings
& updateSettings
API calls there are returning 404.
Go code which was working till early January has started to fail at least since mid-January. The same service account credentials work correctly for calling list
API call for e.g. I was wondering if this is a SDK issue and tried Python too, but seeing the same behaviour there.
On https://alertcenter.googleapis.com on a browser with no credentials:
/v1beta1/settings
throws a 404 which isn't expected/v1beta1/alerts
throws a 401 correctly
Python code sample using google-api-python-client==2.75.0
# alert.py
from google.oauth2 import service_account
from googleapiclient.discovery import build
def main():
credentials = service_account.Credentials.from_service_account_file(
'service_account_credentials.json',
scopes=['https://www.googleapis.com/auth/apps.alerts'],
subject='<email of Google Workspace user authorized to manage alerts>'
)
# Build the service
service = build('alertcenter', 'v1beta1', credentials=credentials)
response = service.v1beta1().getSettings().execute()
# When uncommented, the below call works with the same credentials
# response = service.alerts().list().execute()
print(response)
if __name__ == '__main__':
main()
Golang code sample using google.golang.org/api v0.109.0
// alert.go
package main
import (
"context"
"crypto/tls"
"fmt"
"github.com/hashicorp/go-cleanhttp"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/alertcenter/v1beta1"
"io/ioutil"
"net/http"
"time"
)
func main() {
creds, err := ioutil.ReadFile("service_account_credentials.json")
if err != nil {
fmt.Println(err)
}
config, err := google.JWTConfigFromJSON(creds, alertcenter.AppsAlertsScope)
if err != nil {
fmt.Println(err)
}
config.Subject = "<email of Google Workspace user authorized to manage alerts>"
transport := cleanhttp.DefaultPooledTransport()
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: false,
}
transport.ResponseHeaderTimeout = 30 * time.Second
hc := &http.Client{
Transport: transport,
}
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, hc)
client := config.Client(ctx)
srv, err := alertcenter.New(client)
if err != nil {
fmt.Println(err)
}
fmt.Println(srv)
s, err := srv.V1beta1.GetSettings().Context(ctx).Do()
// When uncommented, the below call works with the same credentials
// s, err := srv.Alerts.List().Context(ctx).Do()
fmt.Println(s)
fmt.Println(err)
}
What steps will reproduce the problem?
- Get the service account credentials JSON file and substitute the path in the code
- Get the Google Workspace user's email and substitute the subject in the code
python3 alert.py
orgo run alert.go
Expected/actual output
I used to get standard get & update settings 200 responses as mentioned in the documentation earlier. Now I get this with the Python code:
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://alertcenter.googleapis.com/v1beta1/settings?alt=json returned "Not Found". Details: "<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/v1beta1/settings</code> was not found on this server. <ins>That’s all we know.</ins>
">
The Golang code also has a similar output now.