04-20-2025 02:12 AM
I am trying to use the ISE API to create my bulk Authorization profiles. I write the following Python Code. This code create Authorization profiles, but I still unable to select and change the the Advanced Attributes parts of the profiles when I create them.
import logging
import pandas as pd
from ciscoisesdk import api, ApiError, ciscoisesdkException
import json
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def create_authorization_profile(api_, policy_name, access_type, profile_name, left_dictionary_name, left_attribute_name, value):
try:
profile_data = {
"name": policy_name,
"profileName": profile_name,
"accessType": access_type,
"advancedAttributes": {
"leftHandSideDictionaryAttribute": [
{
"dictionaryName": left_dictionary_name,
"attributeName": left_attribute_name,
"value": value
}
]
},
"description": "Created via Python bulk script"
}
# Log the request payload
logging.debug(f"Request Data: {json.dumps(profile_data, indent=2)}")
# Make the API call to create the authorization profile
response = api_.authorization_profile.create_authorization_profile(**profile_data)
if hasattr(response, 'response'):
logging.info(f" Profile '{policy_name}' created successfully.")
else:
logging.warning(f" Unexpected response type: {type(response)}")
except ApiError as e:
logging.error(f" API Error while creating profile '{policy_name}': {e}")
if hasattr(e, 'response'):
logging.debug(f"Error Response: {e.response.text}")
except ciscoisesdkException as e:
logging.warning(f" SDK Exception while creating profile '{policy_name}': {e}")
except Exception as e:
logging.exception(f" General error while creating profile '{policy_name}': {e}")
def main():
# Initialize Cisco ISE API client
api_ = api.IdentityServicesEngineAPI(
username="ers-user", # Replace with your username
password="password(", # Replace with your password
base_url="https://10.10.10.10", # Replace with your ISE FQDN or IP
version='3.3', # Match your ISE version
verify=False, # Set True if using trusted certs
debug=True,
uses_api_gateway=True,
uses_csrf_token=False
)
# Load Excel file
excel_path = "C:\\Authorization_policies.xlsx"
try:
df = pd.read_excel(excel_path)
logging.info(f" Loaded Excel file: {excel_path}")
except Exception as e:
logging.error(f" Failed to load Excel file: {e}")
return
# Iterate through each row and create profiles
for index, row in df.iterrows():
policy_name = row.get('Policy Name')
access_type = row.get('Access Type', 'ACCESS_ACCEPT')
profile_name = row.get('Profile Name', 'Cisco')
left_dictionary_name = row.get('Left_dictionaryName')
left_attribute_name = row.get('Left_attributeName')
value = row.get('Value')
if policy_name and left_dictionary_name and left_attribute_name and value:
create_authorization_profile(
api_,
policy_name.strip(),
access_type.strip() if isinstance(access_type, str) else access_type,
profile_name.strip() if isinstance(profile_name, str) else profile_name,
left_dictionary_name.strip(),
left_attribute_name.strip(),
str(value).strip()
)
else:
logging.warning(f" Skipping row {index + 1}: Missing required fields.")
logging.info(" Bulk profile creation completed.")
if __name__ == "__main__":
main()
I will appreciation if you able to help me to write the correct code.
ISE Version : 3.3 Patch 4
Python Version: 3
Solved! Go to Solution.
04-23-2025 03:30 AM
I found the problem I want you to know it as well.
The problem was at advancedAttributes in the code. I should write it advanced_Attributes.
04-23-2025 03:30 AM
I found the problem I want you to know it as well.
The problem was at advancedAttributes in the code. I should write it advanced_Attributes.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide