01-26-2023 08:46 AM
Hi everyone! I hope you're fine,
I'm trying to perform some automations using Python 3 scripts and the Cisco Rest API v4
I'm trying to get interfaces metric data (https://developer.cisco.com/site/prime-infrastructure/documents/api-reference/latest/v4/op/statisticsService/interfaces/metrics/%7Bmetric%7D-GET@_docs/)
The next line for being specific (using Long for measuring from 01 Dec 2022 to 31 Dec 2022):
"https://" + ip + "/webacs/api/v4/op/statisticsService/interfaces/metrics/intraffic.json?startTime=" + start_time + "&endTime=" + end_time +"&metricDataType=TIME_SERIES&device=" + router_ip + "&ifName=" + router_interface
And I'm getting no data (Attached an image of this), but, if I replace the parameters startTime and endTime using timeInterval I get data...
Not sure why is this happening
I'm totally new to the API, so I don't know if something has to be installed or activated in the router (my knowledge about networks is not much)
Hope you can give me a hand
Thank you so much for your time!
Best regards
02-17-2023 09:03 AM
Hi @ipcarlos,
I''m not an expert with Prime or this API but I'm experienced with Python and APIs in general, so these are just my thoughts...
So it looks like the startTime and endTime parameters must be of 'Long' type. My understanding is that we could convert an Integer to Long type in Python2, but Long and Integer types have been merged in Python3. Essentially, all Integers are also Longs in Python3. So, the format of the numbers isn't the issue I think.
Have you tried receiving the response in XML format instead of JSON?
I'm not sure if this is applicable, but have you tried changing the values for these parameters?
You could also trying moving the timestamps to the end of the Request. The example they have adds the time parameter to the end of the request
https://localhost/webacs/api/v4/op/statisticsService/interfaces/metrics/{metric}.json?device=192.168.0.1&ifName=GigabitEthernet0/1&timeInterval=1
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