cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2729
Views
10
Helpful
4
Replies

Cisco Prime 3.0 : Faster ways to get data through web api?

stonent01
Level 1
Level 1

I've been given read only access to Cisco Prime at my company so that I can do location of systems, document ports etc. I'm not officially part of the networking group, but I frequently have to ask them to look things up for me in my day to day work so this access was set up at my request so I don't have to interrupt them as much.

Since the browser based interface is rather slow I read the API documentation and have figured out how to get the data from PowerShell.

For Example:

# Enter the VLAN that you're searching for

$vlan = "130"

# Outputs this line of text to the screen

"Query is running, this can take 10 to 20 seconds"

# This query asks Cisco Prime for the clients that match the query

[XML]$ResultsList = (Invoke-WebRequest -uri "https://CiscoPrime.MyCompany.com/webacs/api/v1/data/ClientDetails?vlan=`"$vlan`"" -Headers $Headers).Content
What that does is builds this URL

https://CiscoPrime.MyCompany.Com/webacs/api/v1/data/ClientDetails?vlan="123" and does a web request.

Cisco prime then returns a list of URLs embedded in XML that have the details of what I'm needing.

The way I'm currently getting the details from this is running a loop and hitting each of those URLs one by one and gathering the data and dumping it into a CSV file which I can use for the list of things I'm looking for.

However hitting each URL one by one is time consuming even in the script as it takes 5 to 10 seconds for each response.

Is there a way using the web API that will just return the detailed results at once in one big block?

1 Accepted Solution

Accepted Solutions

I think you've missed the "." for the .full and .maxResults parameters in your query string. Your queryResponse shows it only returned 100 results as it's filtered out your parameters. The .maxResults=1000 should have returned 247 for "last" instead of 99.

<queryResponse type="ClientDetails" rootUrl="https://prime/webacs/api/v1/data" requestUrl="https://prime/webacs/api/v1/data/ClientDetails?vlan=&quot;123&quot;&amp;full=true&amp;maxResults=1000" responseType="listEntityIds"
count="248" first="0" last="99">

Try copy paste this URL, modifying your hostname and vlan:

https://prime/webacs/api/v1/data/ClientDetails?vlan=123&.full=true&.maxResults=1000

Note the dots before the 'full' and 'maxResults' parameters.

Here's what is returned for me:

<queryResponse last="999" first="0" count="3814" type="ClientDetails" responseType="listEntityInstances" requestUrl="https://prime/webacs/api/v1/data/ClientDetails?vlan=123&amp;.full=true&amp;.maxResults=1000" rootUrl="https://prime/webacs/api/v1/data">
   <entity dtoType="clientDetailsDTO" type="ClientDetails" url="https://prime/webacs/api/v1/data/ClientDetails/336689749">
      <clientDetailsDTO displayName="336689749" id="336689749">
         <apIpAddress>0.0.0.0</apIpAddress>
         <apSlotId>0</apSlotId>
         <associationTime>1471954700268</associationTime>
         <auditSessionId>0A415602000001781C912053</auditSessionId>
         <authenticationAlgorithm>OPENSYSTEM</authenticationAlgorithm>
         <authorizedBy>Authentication Server</authorizedBy>
         <bytesReceived>0</bytesReceived>
         <bytesSent>0</bytesSent>
         <ccxFSVersion>V1</ccxFSVersion>
         <ccxLSVersion>V1</ccxLSVersion>
         <ccxMSVersion>V1</ccxMSVersion>
         <ccxVSVersion>V1</ccxVSVersion>
         <ccxVersion>UNSUPPORTED</ccxVersion>
         <clientAaaOverrideAclApplied>NA</clientAaaOverrideAclApplied>
         <clientAclApplied>NA</clientAclApplied>
         <clientApMode>UNKNOWN</clientApMode>
         <clientInterface>FastEthernet0/8</clientInterface>
         <connectionType>WIRED</connectionType>
         <deviceIpAddress>switchname.domain.com.au</deviceIpAddress>
         <deviceName>switchname.domain.com.au</deviceName>
         <deviceType>Unknown</deviceType>
         <eapType>UNNOWN</eapType>
         <encryptionCypher>UNKNOWN</encryptionCypher>
         <firstSeenTime>1399620253279</firstSeenTime>
         <hreapLocallyAuthenticated>3</hreapLocallyAuthenticated>
         <ifDescr>FastEthernet0/8</ifDescr>
         <ifIndex>10008</ifIndex>
         <ipAddress>x.x.x.x</ipAddress>
         <ipType>IPV4</ipType>
         <location>Unknown</location>
         <macAddress>xx:xx:xx:xx:xx:xx</macAddress>
         <mobilityStatus>LOCAL</mobilityStatus>
         <nacState>NA</nacState>
         <packetsReceived>0</packetsReceived>
         <packetsSent>0</packetsSent>
         <policyType>NA</policyType>
         <policyTypeStatus>AUTHORIZATIONSUCCEEDED</policyTypeStatus>
         <postureStatus>UNKNOWN</postureStatus>
         <protocol>DOT3</protocol>
         <rssi>-128</rssi>
         <securityPolicyStatus>PASSED</securityPolicyStatus>
         <snr>0</snr>
         <speed>SPEED100M</speed>
         <status>ASSOCIATED</status>
         <throughput>0.0</throughput>
         <traffic>0</traffic>
         <updateTime>1471954756030</updateTime>
         <vendor>Dell</vendor>
         <vlan>123</vlan>
         <vlanName>VLAN_NAME</vlanName>
         <webSecurity>DISABLED</webSecurity>
         <wepState>NA</wepState>
         <wgbStatus>REGULARCLIENT</wgbStatus>
         <wiredClientType>NA</wiredClientType>
      </clientDetailsDTO>
   </entity>
</queryResponse>

View solution in original post

4 Replies 4

leesa
Level 1
Level 1

Is there a way using the web API that will just return the detailed results at once in one big block?

You can add &.full=true to the end of your URL and it'll return the full details of each entity rather than just a list of the entities.

The first queryResponse element will show you the "count" of how many items were matched and by default the API will return 100 items of that count per page. The "first" will be a "0" and the "last" will be "99" provided you have more than 100 results.

You can stretch that out to 1000 results per page by appending &.maxResults=1000 on the end of the URL. To then get the next lot of 1000, you'll have to set the firstResult to 1000 and it'll then return 1000-1999. Set firstResult to 2000 and it'll return 2000-2999, etc.

So, your sequence of URLs will be

https://prime/webacs/api/v1/data/ClientDetails?vlan="123"&.full=true&.maxResults=1000

https://prime/webacs/api/v1/data/ClientDetails?vlan="123"&.full=true&.maxResults=1000&.firstResult=1000

https://prime/webacs/api/v1/data/ClientDetails?vlan="123"&.full=true&.maxResults=1000&.firstResult=2000

You can append &.firstResult=0 to the first URL to make it easier to script.

There is a section in the documentation at /webacs/api/v1/?id=paging-doc

I hope that helps.

Thank you for your response.

I tried what you suggested but still seem to be getting basically the same thing. (I got 248 results from my query, but I trimmed it down for the post).

I guess what I'm trying for is a XML file returned that has all of the details for each item in one file.

Similar to how I can go to the web interface and get pull up the client search and tell it I'm looking for everything on VLAN 123 and it shows me the IPs and MACs of all the devices and the switches and ports they are connected to.

<?xml version="1.0" ?>
<queryResponse type="ClientDetails" rootUrl="https://prime/webacs/api/v1/data" requestUrl="https://prime/webacs/api/v1/data/ClientDetails?vlan=&quot;123&quot;&amp;full=true&amp;maxResults=1000" responseType="listEntityIds"
count="248" first="0" last="99">
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108723545" type="ClientDetails">108723545</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108741803" type="ClientDetails">108741803</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108741983" type="ClientDetails">108741983</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108742137" type="ClientDetails">108742137</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108742170" type="ClientDetails">108742170</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108742195" type="ClientDetails">108742195</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108742235" type="ClientDetails">108742235</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108742361" type="ClientDetails">108742361</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108742363" type="ClientDetails">108742363</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108742374" type="ClientDetails">108742374</entityId>
<entityId url="https://prime/webacs/api/v1/data/ClientDetails/108742376" type="ClientDetails">108742376</entityId>
</queryResponse>

I think you've missed the "." for the .full and .maxResults parameters in your query string. Your queryResponse shows it only returned 100 results as it's filtered out your parameters. The .maxResults=1000 should have returned 247 for "last" instead of 99.

<queryResponse type="ClientDetails" rootUrl="https://prime/webacs/api/v1/data" requestUrl="https://prime/webacs/api/v1/data/ClientDetails?vlan=&quot;123&quot;&amp;full=true&amp;maxResults=1000" responseType="listEntityIds"
count="248" first="0" last="99">

Try copy paste this URL, modifying your hostname and vlan:

https://prime/webacs/api/v1/data/ClientDetails?vlan=123&.full=true&.maxResults=1000

Note the dots before the 'full' and 'maxResults' parameters.

Here's what is returned for me:

<queryResponse last="999" first="0" count="3814" type="ClientDetails" responseType="listEntityInstances" requestUrl="https://prime/webacs/api/v1/data/ClientDetails?vlan=123&amp;.full=true&amp;.maxResults=1000" rootUrl="https://prime/webacs/api/v1/data">
   <entity dtoType="clientDetailsDTO" type="ClientDetails" url="https://prime/webacs/api/v1/data/ClientDetails/336689749">
      <clientDetailsDTO displayName="336689749" id="336689749">
         <apIpAddress>0.0.0.0</apIpAddress>
         <apSlotId>0</apSlotId>
         <associationTime>1471954700268</associationTime>
         <auditSessionId>0A415602000001781C912053</auditSessionId>
         <authenticationAlgorithm>OPENSYSTEM</authenticationAlgorithm>
         <authorizedBy>Authentication Server</authorizedBy>
         <bytesReceived>0</bytesReceived>
         <bytesSent>0</bytesSent>
         <ccxFSVersion>V1</ccxFSVersion>
         <ccxLSVersion>V1</ccxLSVersion>
         <ccxMSVersion>V1</ccxMSVersion>
         <ccxVSVersion>V1</ccxVSVersion>
         <ccxVersion>UNSUPPORTED</ccxVersion>
         <clientAaaOverrideAclApplied>NA</clientAaaOverrideAclApplied>
         <clientAclApplied>NA</clientAclApplied>
         <clientApMode>UNKNOWN</clientApMode>
         <clientInterface>FastEthernet0/8</clientInterface>
         <connectionType>WIRED</connectionType>
         <deviceIpAddress>switchname.domain.com.au</deviceIpAddress>
         <deviceName>switchname.domain.com.au</deviceName>
         <deviceType>Unknown</deviceType>
         <eapType>UNNOWN</eapType>
         <encryptionCypher>UNKNOWN</encryptionCypher>
         <firstSeenTime>1399620253279</firstSeenTime>
         <hreapLocallyAuthenticated>3</hreapLocallyAuthenticated>
         <ifDescr>FastEthernet0/8</ifDescr>
         <ifIndex>10008</ifIndex>
         <ipAddress>x.x.x.x</ipAddress>
         <ipType>IPV4</ipType>
         <location>Unknown</location>
         <macAddress>xx:xx:xx:xx:xx:xx</macAddress>
         <mobilityStatus>LOCAL</mobilityStatus>
         <nacState>NA</nacState>
         <packetsReceived>0</packetsReceived>
         <packetsSent>0</packetsSent>
         <policyType>NA</policyType>
         <policyTypeStatus>AUTHORIZATIONSUCCEEDED</policyTypeStatus>
         <postureStatus>UNKNOWN</postureStatus>
         <protocol>DOT3</protocol>
         <rssi>-128</rssi>
         <securityPolicyStatus>PASSED</securityPolicyStatus>
         <snr>0</snr>
         <speed>SPEED100M</speed>
         <status>ASSOCIATED</status>
         <throughput>0.0</throughput>
         <traffic>0</traffic>
         <updateTime>1471954756030</updateTime>
         <vendor>Dell</vendor>
         <vlan>123</vlan>
         <vlanName>VLAN_NAME</vlanName>
         <webSecurity>DISABLED</webSecurity>
         <wepState>NA</wepState>
         <wgbStatus>REGULARCLIENT</wgbStatus>
         <wiredClientType>NA</wiredClientType>
      </clientDetailsDTO>
   </entity>
</queryResponse>

Yep you were right, I just caught that a few minutes ago and was coming back to say I realized what it was.  I had thought it was a mistake in the url.

I got some results this time.

As for the 0 to 100, I think that's a hard limit they have set so I will have to request multiple times if it goes over.

Thanks!