diff --git a/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py b/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py index 3627f23..a41097a 100644 --- a/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py +++ b/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py @@ -2,6 +2,7 @@ from typing import Any import requests +import logging class BaremetricsHandler(object): def initialize(self, bot_handler: Any) -> None: @@ -20,6 +21,19 @@ class BaremetricsHandler(object): 'List the sources', 'List the plans for the source', 'List the customers in the source', 'List the subscriptions in the source'] + self.check_api_key() + + def check_api_key(self) -> None: + url = "https://api.baremetrics.com/v1/account" + test_query_response = requests.get(url, headers=self.auth_header) + test_query_data = test_query_response.json() + + try: + if test_query_data['error'] == "Unauthorized. Token not found": + logging.error('API Key not valid. Please see doc.md to find out how to get it.') + except KeyError: + pass + def usage(self) -> str: return ''' This bot gives updates about customer behavior, financial performance, and analytics