Monday, July 8, 2019

POST to ERS for ISE with JSON

Hey guys,

having some trouble. I am working on a script to automate Network Device and Network Device Groups creations using python with the requests module. I am trying to do this with using JSON to push the actually code to the ISE API. I am able to get a list of devices and device groups, as well as delete them, but when I use JSON in the requests.posts to actually create one, I usually get a 401 error... It makes no sense knowing that I can use this same account to delete and get using requests.get/delete.

Here is an example of my code:

import requests

import requests.auth

import getpass

import json

Username = input("Enter API Username:")

Password = getpass.getpass("Enter API Password:")

headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}

ISE = requests.post("https://x.x.x.x:9060/ers/config/networkdevicegroup", verify=False, auth=(Username, Password), headers=headers, json={

"NetworkDeviceGroup" : {

"id" : "123456789",

"name" : "ERS Group",

"description" : "TEST ERS",

"othername" : "TEST"

}

})

print(ISE.status_code)

print(ISE.text)

I have even tried putting the json code into a variable and passing it that way and no luck..

If I try enough times it will get the 401 error, but if i recreate the ERS admin user and do it for the first time I get the following:

400

{

"ERSResponse" : {

"operation" : "POST-create-networkdevicegroup",

"messages" : [ {

"title" : "Validation Error - Illeagal values: [The name should have at least type and name, delimited by pound sign, The name's first part (before the first pound sign delimiter) should be equal to group's type provided.]",

"type" : "ERROR",

"code" : "Application resource validation exception"

} ],

"link" : {

"rel" : "related",

"href" : "https://x.x.x.x9060/ers/config/networkdevicegroup",

"type" : "application/xml"

}

}

}

Any help or suggestions would be highly appreciated.



No comments:

Post a Comment