Forum Discussion
Direct URIs for iControlREST calls
I am a newbie and was trying to get my feet wet with REST calls. As such, I am writing (rather attempting to write) a simple call which will get me the serial and the installed version from a LTM. I am using the path "/mgmt/tm/sys/hardware/?expandSubcollections=true". However the resulting json is huge with quite a few nesting & is quite overwhelming. Is there a shorter or direct URI I should be using ?
2 Replies
- tatmotiv
Cirrostratus
Try omitting the ?expandSubcollections=True. Cannot try it out at the moment, but I think the serial should be included in the json even without the subcollections. If not, find the subcollection that includes the serial and call that subcollection directly by using the selflink contained within.
- matthew_wedlow_
Nimbostratus
If you are trying to get the serial number out of the JSON output you can simply walk through the nested JSON until you get to what you're looking for.
Example for Serial Number path
["entries"]["https://localhost/mgmt/tm/sys/hardware/system-info"]["nestedStats"]["entries"]["https://localhost/mgmt/tm/sys/hardware/system-info/0"]["nestedStats"]["entries"]["bigipChassisSerialNum"]["description"]So in python 2.7 using requests it would look like this
import json import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) Fixes certificate warning BS def GetSerial(URI): request = requests.session() request.auth = ('USERNAME' , 'PASSWORD') request.verify = False request.headers.update({'Content-Type':'application/json'}) response = request.get(URI) data = response.json() parse the JSON output for the Serial Number print (data["entries"]["https://localhost/mgmt/tm/sys/hardware/system-info"]["nestedStats"]["entries"]["https://localhost/mgmt/tm/sys/hardware/system-info/0"]["nestedStats"]["entries"]["bigipChassisSerialNum"]["description"]) uri = 'https://X.X.X.X/mgmt/tm/sys/hardware' GetSerial(uri)
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com