- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Get Organization Clients Search Breakout "Records" Section
I am trying to breakout the "Records Section" from the response. Is this possible? Below is the code I have currently. It returns the MAC and the whole record section.
def find_device():
clearconsole()
API_KEY = get_meraki_api_key()
dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)
organization_id = '412637'
mac = input ('Which device are you trying to find (xx:xx:xx:xx:xx:xx): ')
response = dashboard.organizations.getOrganizationClientsSearch(
organization_id, mac, total_pages='all'
)
fields = ['mac','records']
for field in fields:
print ('\n' + 'Here is what I found: ' + '\n')
print (f"{field}: {response[field]}")
Solved! Go to solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The records section in the API response is a list of nested dictionary which you have to parse to retrieve the keys you need.
For example the structure of this API response is something like this -
API response = { key:value, record:{ [ { key1:value1, key2:value2, etc.} ] } }
In order to access the inner values of this nested dictionary you can do
record = response['records']
print ('\n' + 'Here is what I found: ' + '\n')
print("IP is ", record[0]['ip'])
print("SwitchPort is ", record[0]['switchport'])
print("Status is ", record[0]['status'])
You can learn about nested dictionaries here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure, but I think it should be more like:
mac =response['mac']
records = response['records']
for record in records:
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will give this a try and let you know. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want just the MAC address of the client, you don't need to run the for loop printing all the response fields. Just do -
print ('\n' + 'Here is what I found: ' + '\n')
print ("mac is", response['mac'])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yeah I can get the MAC to display but I want to pull certain values out of the records section of the data. Lets say I want to show the following:
- MAC
- IP
- Switchport
- Status
MAC is fine but the other are part of the Records section.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The records section in the API response is a list of nested dictionary which you have to parse to retrieve the keys you need.
For example the structure of this API response is something like this -
API response = { key:value, record:{ [ { key1:value1, key2:value2, etc.} ] } }
In order to access the inner values of this nested dictionary you can do
record = response['records']
print ('\n' + 'Here is what I found: ' + '\n')
print("IP is ", record[0]['ip'])
print("SwitchPort is ", record[0]['switchport'])
print("Status is ", record[0]['status'])
You can learn about nested dictionaries here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you this works perfect and now know how to get that info out.
