cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3315
Views
15
Helpful
3
Replies

Prime Infrastructure api - > 1000 maxResults?

phoffswell
Level 1
Level 1

Hi -

We pull our wifi association data out via api with the following URL:

https://prime/webacs/api/v1/data/Clients.json?.maxResults=1000&.full=true&status=ASSOCIATED

Works great, except that we have more than 1000 associations at peak.

https://prime/webacs/api/v1/data/Clients.json?.maxResults=1001&.full=true&status=ASSOCIATED

Returns an apache tomcat error:

HTTP Status 503 - Requested maxResults: 1001 is greater than allowed maximum: 1000


type Status report

message Requested maxResults: 1001 is greater than allowed maximum: 1000

description The requested service is not currently available.


Apache

What gives?  How can we adjust maxResults for our Cisco Prime Infrasture api?

Thanks for any ideas -

1 Accepted Solution

Accepted Solutions

phoffswell
Level 1
Level 1

Greetings.

Solved my own problem by using the paging feature on the api: https://prime/webacs/api/v1/?id=paging-doc

Instead of trying to get all your records in one api call, just get them 500 at a time:

Loop through your results by pages until your call returns 0:

https://prime/webacs/api/v1/data/Clients.json?.firstResult=0&.maxResults=500&.full=true&status=ASSOCIATED

https://prime/webacs/api/v1/data/Clients.json?.firstResult=500&.maxResults=500&.full=true&status=ASSOCIATED

https://prime/webacs/api/v1/data/Clients.json?.firstResult=1000&.maxResults=500&.full=true&status=ASSOCIATED

.

.

.

I hope this helps someone else some day. 

View solution in original post

3 Replies 3

phoffswell
Level 1
Level 1

Greetings.

Solved my own problem by using the paging feature on the api: https://prime/webacs/api/v1/?id=paging-doc

Instead of trying to get all your records in one api call, just get them 500 at a time:

Loop through your results by pages until your call returns 0:

https://prime/webacs/api/v1/data/Clients.json?.firstResult=0&.maxResults=500&.full=true&status=ASSOCIATED

https://prime/webacs/api/v1/data/Clients.json?.firstResult=500&.maxResults=500&.full=true&status=ASSOCIATED

https://prime/webacs/api/v1/data/Clients.json?.firstResult=1000&.maxResults=500&.full=true&status=ASSOCIATED

.

.

.

I hope this helps someone else some day. 

That's just come in handy - thanks!

p.juarezponte
Level 1
Level 1

I know this is an old post which was resolved, but in order to help someone which wants to make an automatic query (by using python), I am sharing this.

It returns a list with all the results in blocks (with 1000 devices)

 

def get_inventory():
    resultados = []
    print("Lanzando consulta de inventario de switches...")
    args = {
        "productFamily": '"Switches and Hubs"',  #Al pedir un tipo concreto debe ir con dobles comillas en la petición
        ".full": "true",
        ".maxResults": 1000
    }
    r = session.get(url + "data/Devices.json", params=args)
    r_json = r.json()
    resultados.append(r_json['queryResponse']['entity'])
    equipos = r.json()['queryResponse']['@count']
    last = r.json()['queryResponse']['@last']
    contador = 2
    while equipos > last+1:
        print(f"Obteniendo página {contador}")
        args[".firstResult"] = last+1
        r = session.get(url + "data/Devices.json", params=args)
        r_json = r.json()
        resultados.append(r_json['queryResponse']['entity'])
        last = r.json()['queryResponse']['@last']
        contador += 1
        time.sleep(1)

    return resultados
Review Cisco Networking products for a $25 gift card