Alert Center API

The Alert Center API lets you manage alerts affecting your domain. An alert is a warning of a potential security issue that Google has detected. Alerts include the following information:

  • Source that the alert originated from.
  • Name of the alert.
  • Time this alert happened.
  • Specific data associated with this alert.

Domain administrators can see and manage alerts manually from the Google Admin console. The Alert Center API lets apps you build retrieve alert data and alert feedback. The API can also create new alert feedback for existing alerts.

For example, a monitoring app could use the Alert Center API to retrieve the most recent alerts for a domain, prioritize them, and then notify members of your organization. After your team responds to the alert, the app could then attach feedback to the alert based on their findings.

Use Alert Center API

Before using the Alert Center API you need to set up a new Cloud Platform project and enable Alert Center API. Your project must use a service account when accessing the API.

Once your app has a Cloud project that meets the prequisties and is properly [authorized]((/admin-sdk/alertcenter/guides/authorizing), it can make Alert Center API REST requests. Making API requests is easier when using the available client libraries.

The following example shows how to list available alerts using the API:

Java

// First, authorize the API and create a client to make requests with.
URL serviceAccountUrl = AuthUtils.class.getResource("/client_secret.json");
GoogleCredentials credentials =  ServiceAccountCredentials
    .fromStream(serviceAccountUrl.openStream())
    .createDelegated("admin@xxxx.com")
    .createScoped(Collections.singleton("https://www.googleapis.com/auth/apps.alerts"));
ApacheHttpTransport transport = new ApacheHttpTransport();
HttpCredentialsAdapter adapter = new HttpCredentialsAdapter(credentials);
AlertCenter alertCenter = new AlertCenter.Builder(transport, new JacksonFactory(),
    adapter)
    .setApplicationName("Alert Center client")
    .build();

// List alerts in pages, printing each alert discovered.
ListAlertsResponse listResponse = alertCenter.alerts().list().setPageSize(20).execute();
while (listResponse.getAlerts() != null) {
  for (Alert alert : listResponse.getAlerts()) {
    lastAlertId = alert.getAlertId();
    System.out.println(alert);
  }
  if (listResponse.getNextPageToken() == null || listResponse.getNextPageToken().isEmpty()) {
    break;
  }
  listResponse = alertCenter.alerts().list().setPageToken(listResponse.getNextPageToken())
      .setPageSize(20).execute();
}