question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alerts API returns 400 Error Part 2

See original GitHub issue

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you’ve tried the usual “quick fixes”:

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS: Darwin 18.6.0
  • Python version: 3.6.5
  • pip version: 19.2.3
  • google-api-python-client version:1.7.8

Steps to reproduce

  1. This is a clone of this issue: https://github.com/googleapis/google-api-python-client/issues/645
  2. My SA was made through the Using OAuth 2.0 for Server to Server Applications documentation provided as further reading to the original documentation page. I granted domain-wide access to the service account from the Servie Account panel and used that to grab the client ID.

Code:

from googleapiclient.discovery import build
from google.oauth2 import service_account

class AlertCenterExtractor:

    def __init__(self):

        # build servie and scopes
        self.scopes = ["https://www.googleapis.com/auth/apps.alerts"]
        self.credentials = service_account.Credentials.from_service_account_file(
                "SERVICEACCOUNT.JSON", scopes=self.scopes)
        self.service = build('alertcenter', 'v1beta1', credentials=self.credentials).alerts()

    """ Gets alerts and writes them to output directory. """
    def get_alerts(self):
        recent_alerts = self.service.list(customerId="my_customer_id").execute()

if __name__ == '__main__':
    alert_center_class = AlertCenterExtractor()
    alert_center_class.get_alerts()

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
iuhfiajfoisjfdisajcommented, Nov 15, 2019

I have it working! I follow the google person’s comments and added in ‘subject=myemail@mydomain.com’. Small test case that works for me:

import json
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2 import service_account

def main():
    scopes = ["https://www.googleapis.com/auth/apps.alerts"]
    credentials = service_account.Credentials.from_service_account_file("serviceacccreds.json", subject="fd@spellbook.io", scopes=scopes)
    service = build('alertcenter', 'v1beta1', credentials=credentials).alerts()

    recent_alerts = service.list().execute().get("alerts", [])

    print(json.dumps(recent_alerts, indent=2))


if __name__ == '__main__':
    main()
0reactions
4ndygucommented, Nov 15, 2019

Hi! this ended up working for us too - It seems i chose the wrong subject. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alerts API returns 400 for Python [144282691] - Issue Tracker
2. My SA was made through the `Using OAuth 2.0 for Server to Server Applications` documentation provided as further reading to the original...
Read more >
FCM api 'Bad request 400' error - Stack Overflow
I'm trying to implement sending notifications via new FCM api protocols. ... Now when I send request I'm receiving Bad request 400 error....
Read more >
Relic Solution: How to Use the Infrastructure Alerts REST API ...
Relic Solution: How to Use the Infrastructure Alerts REST API to Its Maximum Potential - Part 2: Compound Alert Conditions.
Read more >
Handle API errors | Google Calendar
400 : Bad Request; 401: Invalid Credentials; 403: User Rate Limit Exceeded; 403: Rate Limit ... The Calendar API returns two levels of...
Read more >
Solved: 400 error when creating issue via REST API
Foster ,. welcome to the Atlassian community! Please look at the documentation for Jira cloud - create issue section. The correct url is:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found