'get-all-internal-users.py' Source Code

#!/usr/bin/env python

###########################################################################
#                                                                         #
# This script demonstrates how to use the ISE ERS internal users          #
# API  by executing a Python script.                                      #
#                                                                         #
# SECURITY WARNING - DO NOT USE THIS SCRIPT IN PRODUCTION!                #
# The script allows connections to SSL sites without trusting             #
# the server certificates.                                                #
# For production, it is required to add certificate check.                #
#                                                                         #
# Usage: get-all-internal-users.py <ISE host> <ERS user> <ERS password>   #
###########################################################################

import http.client
import base64
import ssl
import sys

# host and authentication credentials
host = sys.argv[1] # "10.20.30.40"
user = sys.argv[2] # "ersad"
password = sys.argv[3] # "Password1"


conn = http.client.HTTPSConnection("{}:9060".format(host), context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))

creds = str.encode(':'.join((user, password)))
encodedAuth = bytes.decode(base64.b64encode(creds))

headers = {
    'accept': "application/json",
    'authorization': " ".join(("Basic",encodedAuth)),
    'cache-control': "no-cache",
    }

conn.request("GET", "/ers/config/internaluser/", headers=headers)

res = conn.getresponse()
data = res.read()

print("Status: {}".format(res.status))
print("Header:\n{}".format(res.headers))
print("Body:\n{}".format(data.decode("utf-8")))

Execution

python get-all-internal-users.py 10.20.30.40 ersad Password1

Status: 200 (OK)
Header:
Cache-Control: no-cache, no-store, must-revalidate
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONIDSSO=9CA59D468388B1E7A37718CD338A4CCD; Path=/; Secure; HttpOnly
Set-Cookie: APPSESSIONID=EDE7764ECB02F15531A3457E54BF88BD; Path=/ers; Secure; HttpOnly
Pragma: no-cache
Date: Thu, 01 Dec 2016 17:06:23 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 667
Server: 


Body:
{
  "SearchResult" : {
    "total" : 2,
    "resources" : [ {
      "id" : "f330048f-cfb0-45db-8ef0-39efc650b711",
      "name" : "chris",
      "description" : "",
      "link" : {
        "rel" : "self",
        "href" : "https://10.20.30.40:9060/ers/config/internaluser/f330048f-cfb0-45db-8ef0-39efc650b711",
        "type" : "application/xml"
      }
    }, {
      "id" : "5bedbaf5-f627-4465-9def-00824b0bf58c",
      "name" : "doug",
      "description" : "",
      "link" : {
        "rel" : "self",
        "href" : "https://10.20.30.40:9060/ers/config/internaluser/5bedbaf5-f627-4465-9def-00824b0bf58c",
        "type" : "application/xml"
      }
    } ]
  }
}