cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
6052
Views
35
Helpful
10
Replies

Cisco ISE ERS APIs for Network Devices to get a device list with all ip addresses and device names

o.akymenko
Level 1
Level 1

Does anybody know how to use the ERS API in ISE, to export all the switches/wlc's (network devices) ?
I need GET ALL request with Network devices.

In API Documentation there are just two possibilities.

Method GET
Url: https://hostname:9060/ers/config/networkdevice

Method GET
Url: https://hostname:9060/ers/config/networkdevice/{id}

And I want to get link to hole info about all networkdevices (like with the second GET id) in one list

1 Accepted Solution

Accepted Solutions

When you are getting the list of the devices you are getting their ID, Names and Link.

 

  "id": "9d362e00-fe4d-11e7-87dc-500f80ddff18",
        "name": "ISE_EST_Local_Host",
        "link": {
          "rel": "self",
          "href": "https://IP:9060/ers/config/networkdevice/9d362e00-fe4d-11e7-87dc-500f80ddff18",
          "type": "application/json"
        }

 

Inside of Link you have Href value with a valid link request to get all the information from the specific device using its ID

e.g. 9d362e00-fe4d-11e7-87dc-500f80ddff18 in my example

 

Method: 	GET
URI: 	https://IP:9060/ers/config/networkdevice/{id}
HTTP 'Content-Type' Header:	application/xml | application/json
HTTP 'Accept' Header:	application/xml | application/json

Make sure you specify Accept and Content-type in the new requests, cause they are mandatory and this is what your error message is about.

View solution in original post

10 Replies 10

Gennady Yakubovich
Cisco Employee
Cisco Employee

In ISE REST API there is a method called GET-ALL for network devices 

https://hostname:9060/ers/sdk#Get-All

Will it work for you? 

Thanks

If you have less than 100 devices total you could use following link to retrieve all of them

 

GET /ers/config/networkdevice?size=100

 

Max resources per page cannot be more then 100 resources. You need to use paging to retrieve all resources.

This is a little snippet from my code to get all records if you have more then 100...

 

def get_device_list(s):
    """
    Return list of the Network Devices
    Maximum is 100 devices per page ?size=100
    Go through the pages &page = 1
    """
    url = "https://" + ISE_SERVER + ":9060/ers/config/networkdevice?size=100&page="
    url = url + "1"
     resp= requests.request("GET", url, data=payload, headers=headers, params=querystring)
    
    device_list = []

    if resp.status_code == 200:
        result  = resp.json()['SearchResult']
        total = result['total']
        pages = total / 100 + 1
        for page in range (1, int(pages + 1)):
            resp= requests.request("GET", url + str(page), data=payload, headers=headers, params=querystring)
            if resp.ok:
                result = resp.json()['SearchResult']['resources']
                for item in result:
                    device = {}
                    device['id'] = item['id']
                    device['name'] = item['name']
                    """ Not all devices has description field """
                    # device['description'] = item['description']
                    device['link'] = item['link']['href']
                    device_list.append(device)

    return device_list

 

 

 

 

 

 

 

 

This is great, thanks for sharing.

 

Is there anyway, you can share more code so I can test this function out in my IDE?  Specifically, the payload, headers and querystring.

 

Thanks.

 

   resp= requests.request("GET", url, data=payload, headers=headers, params=querystring)

 

You could try with an empty payload and querystring

 

url = "https://IP_ADRESS:9060/ers/config/networkdevice"
payload = ""
querystring = ""
headers = {
'Accept': "application/json",
'Content-Type': "application/json",
'Authorization': "Basic ZXJzX2FkbWluOnBhc3N3b3JkCg=="
}

 

Where Auth is username and password encoded with Base64

e.g. 

echo ZXJzX2FkbWluOnBhc3N3b3JkCg== | base64 -d
ers_admin:password

I got it work and got all resources from ISE. Thanks for the quick response!

One thing though, why can't I see everything in the network device's resource, like parameters and their set values in the RADIUS Authentication Settings, IP, etc. Below is all I got back, only 3 fields per returned resource item.

{ 'id': '7c0138d0-e157-11e9-bedf-005056bf3145',
'link': 'https://<ISE-server-IP>:9060/ers/config/networkdevice/7c0138d0-e157-11e9-bedf-005056bf3145',
'name': 'abc'}

When I clicked on that URL link, I got this error message. Do you or anyone get the same thing? I included the code snippet at the end as well (note, I turned off ssl verification on purpose, to address the ssl handshake issue).

<ns3:ersResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns3="ers.ise.cisco.com" operation="GET-get-networkdevice">
<link rel="related" href="https://<ISE-server-IP>:9060/ers/config/networkdevice/7c00eab0-e157-11e9-bedf-005056bf3145" type="application/xml"/>
<messages>
<message type="ERROR" code="Resource media type exception">
<title>
Illeagal Request Header: one or more of 'accept' / 'content-type' / 'ers-media-type' headers is not supported.
</title>
</message>
</messages>
</ns3:ersResponse>

payload = ""
querystring = ""

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

url = "https://" + ISE_SERVER + ":9060/ers/config/networkdevice?size=100&page="
url = url + "1"
resp= requests.request("GET", url, data=payload, headers=headers, params=querystring, verify=False)

Why my last post got removed and was tagged as a spam? I don't see your last response either Sergey. Can you please respond again?

This is from the SDK page.  Maybe, I have to query for those attributes?  There is no instruction on how to do that though.  

Maybe Cisco experts here can help shred lights on that.

 

I got the same thing via postman, only 3 fields.

 

picture.png

I got it work and got all resources from ISE. Thanks for the quick response!

One thing though, why can't I see everything in the network device's resource, like parameters and their set values in the RADIUS Authentication Settings, IP, etc. Below is all I got back, only 3 fields per returned resource item.

{ 'id': '7c0138d0-e157-11e9-bedf-005056bf3145',
'link': 'https://<ISE-server-IP>:9060/ers/config/networkdevice/7c0138d0-e157-11e9-bedf-005056bf3145',
'name': 'abc'}

When I clicked on that URL link, I got this error message. Do you or anyone get the same thing? I included the code snippet at the end as well (note, I turned off ssl verification on purpose, to address the ssl handshake issue).  There is a page (my next post) about resource attributes on the SDK page, but no instructions on how to access those attributes.  

<ns3:ersResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns3="ers.ise.cisco.com" operation="GET-get-networkdevice">
<link rel="related" href="https://<ISE-server-IP>:9060/ers/config/networkdevice/7c00eab0-e157-11e9-bedf-005056bf3145" type="application/xml"/>
<messages>
<message type="ERROR" code="Resource media type exception">
<title>
Illeagal Request Header: one or more of 'accept' / 'content-type' / 'ers-media-type' headers is not supported.
</title>
</message>
</messages>
</ns3:ersResponse>

payload = ""
querystring = ""

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

url = "https://" + ISE_SERVER + ":9060/ers/config/networkdevice?size=100&page="
url = url + "1"
resp= requests.request("GET", url, data=payload, headers=headers, params=querystring, verify=False)

When you are getting the list of the devices you are getting their ID, Names and Link.

 

  "id": "9d362e00-fe4d-11e7-87dc-500f80ddff18",
        "name": "ISE_EST_Local_Host",
        "link": {
          "rel": "self",
          "href": "https://IP:9060/ers/config/networkdevice/9d362e00-fe4d-11e7-87dc-500f80ddff18",
          "type": "application/json"
        }

 

Inside of Link you have Href value with a valid link request to get all the information from the specific device using its ID

e.g. 9d362e00-fe4d-11e7-87dc-500f80ddff18 in my example

 

Method: 	GET
URI: 	https://IP:9060/ers/config/networkdevice/{id}
HTTP 'Content-Type' Header:	application/xml | application/json
HTTP 'Accept' Header:	application/xml | application/json

Make sure you specify Accept and Content-type in the new requests, cause they are mandatory and this is what your error message is about.

Yes, I realized that and expanded my code and got all the attributes.  Thanks again!

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: