NOTE: This is the full script - not the parts! ============================================== import requests import json import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) ISE_HOSTNAME="10.1.1.30" ISE_API_URL=f"https://{ISE_HOSTNAME}/api/v1" ISE_USERNAME="admin" ISE_PASSWORD="1234QWer" session = requests.Session() session.auth = (ISE_USERNAME, ISE_PASSWORD) session.headers.update({ "Accept": "application/json", "Content-Type": "application/json" }) TIMEOUT=(5,10) VERIFY=False def get_endpoints(session): response = session.get(ISE_API_URL + "/endpoint", timeout=TIMEOUT, verify=VERIFY) print(f"Response HTTP Status Code - {response.status_code}") print(f"Response - {response.json()}") def load_inventory(file): with open(file, "r", encoding="utf-8") as f: return json.load(f) def create_endpoints(session, inventory): for endpoint in inventory: payload = { "mac": endpoint["mac"], "device_type": endpoint["device_type"], "name": endpoint["name"] } session.post(ISE_API_URL + "/endpoint", json=payload, timeout=TIMEOUT, verify=VERIFY) print(f"Endpoint {endpoint[‘name’]} has been created.") get_endpoints(session) print(load_inventory("inventory.json")) inventory = load_inventory("inventory.json") create_endpoints(session, inventory) get_endpoints(session) Improvements: def load_inventory(file): try: with open(file, "r", encoding="utf-8") as f: return json.load(f) except FileNotFoundError: raise FileNotFoundError("Inventory file not found") except json.JSONDecodeError as e: raise ValueError(f"Invalid JSON in {file}") def get_endpoints(session, size=2): all_items = [] page = 1 print(f"Reading endpoints in pages of size {size}") while True: params = {"page": page, "size": size} r = session.get(ISE_API_URL + "/endpoint", params=params, timeout=TIMEOUT, verify=VERIFY) print(f"GET {r.url} -> {r.status_code}") r.raise_for_status() data = r.json() if not data: break print(f"Page {page} items = {len(data)}") all_items.extend(data) if len(data) < size: # Found the last page break page += 1 print(f"Total endpoints fetched: {len(all_items)}") inventory.json: [ { "mac": "00:11:22:33:44:01", "device_type": "laptop", "name": "hr-laptop-01" }, { "mac": "00:11:22:33:44:02", "device_type": "laptop", "name": "hr-laptop-02" }, { "mac": "00:11:22:33:44:03", "device_type": "laptop", "name": "hr-laptop-03" }, { "mac": "00:11:22:33:44:04", "device_type": "laptop", "name": "hr-laptop-04" }, { "mac": "00:11:22:33:44:05", "device_type": "laptop", "name": "hr-laptop-05" } ]