'get-guest-user-by-id.py' Source Code

#!/usr/bin/env python

###########################################################################
#                                                                         #
# This script demonstrates how to get the Guest user through ISE ERS      #
# 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-guest-user-by-id.py <ISE host><SponsorUser><SponsorPassword> #
# <Guest User ID>														  #
###########################################################################

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] # "sponsor"
password = sys.argv[3] # "Password1"
guest_user_id = sys.argv[4]  # "4ed8aa40-b6ef-11e6-8c86-0242d54b863b"

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

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/guestuser/{}".format(guest_user_id), 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-guest-user-by-id.py 10.20.30.40 sponsor Password1 4ed8aa40-b6ef-11e6-8c86-0242d54b863b

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: 897
Server: 


Body:
{
  "GuestUser": {
    "id": "a63fafc1-c22c-11e6-ab89-0242fb4b45f0",
    "name": "5lz8g5",
    "guestType": "Contractor (default)",
    "status": "SUSPENDED",
    "sponsorUserName": "sp",
    "sponsorUserId": "a8238d30-c177-11e6-97d0-000c29b9cdef",
    "statusReason": "Contract closed",
    "guestInfo": {
      "userName": "5lz8g5",
      "password": "0070",
      "creationTime": "12/14/2016 10:39",
      "enabled": false,
      "notificationLanguage": "English"
    },
    "guestAccessInfo": {
      "validDays": 1,
      "fromDate": "12/14/2016 10:39",
      "toDate": "12/14/2016 23:59",
      "location": "San Jose"
    },
    "customFields": {}
  }
}