Skip to content

Python requests library

With a little bit of boilerplate code, you can use the Python requests library to make API calls.


Zenoss recommends using Python with the zenApiLib rather than the requests library.

Get a list of devices

  1. Import the requests and json libraries; pprint is optional.

    import requests, json, pprint
  2. Set your router endpoint URL, headers, SSL verification, and your username and password.

    api_endpoint = ''
    api_headers = {'Content-Type': 'application/json'}
    api_ssl = True
    api_username = 'myApiUsername'
    api_password = 'my$up3rS3cUr3ApiP@$$w0rd'
  3. Build the API request.

    api_action = 'DeviceRouter'
    api_method = 'getDevices'
    api_data = []
    payload = json.dumps({'action': api_action,
                          'method': api_method,
                          'data': api_data,
                          'tid': 1})
  4. Make the API request.

    response =,
                             auth=(api_username, api_password),
  5. Use pprint to view the result.