Opsgenie Python Account API

To use the Account functionalities of Opsgenie's API via the Python SDK you will first have to import the SDK library and (configure)(doc:opsgenie-python-api-v2-1#section-client-initialization) it with the API Key that you procured from your Opsgenie Integrations. For additional configurations, you may refer to the Python SDK Configurations page present in the Opsgenie documentation.

# Importing relevant Opsgenie SDK libraries including the Alert API client
import opsgenie_sdk

class Example:
    def __init__(self, opsgenie_api_key):
        self.conf = self.conf = opsgenie_sdk.configuration.Configuration()
        self.conf.api_key['Authorization'] = '<Your-API-Key>'

        self.api_client = opsgenie_sdk.api_client.ApiClient(configuration=self.conf)
        self.account_api = opsgenie_sdk.AccountApi(api_client=self.api_client)

Get Account Info

You can get Account information pertinent to your account using the Alert client that is initialized prior to performing any other Opsgenie API functionality.

To get information related to your account, use the get_info() function which returns a GetAccountInfoResponse. Check the Account API documentation for more.

def get_info(self):
  try:
    info_response = self.account_api.get_info()
    print(info_response)
    return info_response
  except ApiException as err:
    print("Exception when calling AccountApi->get_info: %s\n" % err)

Did this page help you?