'Get requests to Google Chronicle using API KEY in python

Im trying to make some GET requests in Google Chronicle using only API KEY.

I found this code but it only work with json credentials:

def call_list_alerts():
  import os
  from google.oauth2 import service_account
  from googleapiclient import _auth

  SCOPES = ['https://www.googleapis.com/auth/chronicle-backstory']
  SERVICE_ACCOUNT_FILE = os.path.join(os.environ['HOME'], 'bk_credentials.json') 

  credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

  http_client = _auth.authorized_http(credentials)

  BACKSTORY_API_V1_URL = 'https://backstory.googleapis.com/v1'
  LIST_ALERTS_URL = '{}/alert/listalerts?start_time=2019-10-15T00:00:00Z&end_time=2019-10-17T00:00:00Z&page_size=1'.format
  (BACKSTORY_API_V1_URL)

  response = http_client.request(LIST_ALERTS_URL, 'GET')

  if response[0].status == 200:
    alerts = response[1]
    print(alerts)
  else:
    err = response[1]
    print(err)

How can i achieve this using API key and not service account?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source