I am trying to get a list of alerts from the GSuite Alert Center API in a Node JS application.
I created a Service Account at the IAM & Admin page, checked the Enable G Suite Domain-wide Delegation
checkbox, and generated a JSON file with access keys set.
Then I went to the Admin Console -> Security -> API controls -> Domain-wide Delegation
and registered the Service Account by its Client ID with the https://www.googleapis.com/auth/apps.alerts
scope.
The code was taken from the example provided in google-api-nodejs-client and basically looks like
const { google } = require('googleapis');
const alertcenter = google.alertcenter('v1beta1');
const auth = new google.auth.GoogleAuth({
keyFile: 'Path/to/my/file/with/accessKeys'
scopes: ['https://www.googleapis.com/auth/apps.alerts'],
});
const client = await auth.getClient();
google.options({auth: client});
const res = await alertcenter.alerts.list();
What I am getting back from the API is the 'customer id could not be inferred from the request or caller identity.' error message.
I tried to pass the customer ID as a parameter to the list() method since it is described as its legit parameter. Like this
const res = await alertcenter.alerts.list({ customerId: 'my-customer-id' });
As a result, I only got another error message: Request contains an invalid argument.
What do I do wrong?