Hi All
Looks to pull all my networks but only want the id and name to be printed. Here is what I have:
import meraki
from pprint import pprint
# Defining your API key as a variable in source code is discouraged.
# This API key is for a read-only docs-specific environment.
# In your own code, use an environment variable as shown under the Usage section
# @ https://github.com/meraki/dashboard-api-python/
API_KEY = ''
dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)
organization_id = ''
response = dashboard.organizations.getOrganizationNetworks(
organization_id, total_pages='all'
)
fields = [id, name]
for field in fields:
pprint (f"{field}: {response[field]}")
Suggestions...keep getting error about the fields = [id, name]
Traceback (most recent call last):
File "/mnt/m2ssd/python/meraki_get_network_id.py", line 19, in <module>
fields = [id, name]
^^^^
NameError: name 'name' is not defined
Solved! Go to solution.
Don't change the value in RED.
fields = ['id', 'name']
for item in response:
for field in fields:
pprint(f"{field}: {item[field]}")
The error you’re seeing is because id and name are not defined as strings in your list. In Python, strings should be enclosed in quotes.
fields = ['id', 'name']
ok so when I do that I get
Traceback (most recent call last):
File "/mnt/m2ssd/python/meraki_get_network_id.py", line 22, in <module>
pprint (f"{field}: {response[field]}")
~~~~~~~~^^^^^^^
TypeError: list indices must be integers or slices, not str
In Python, lists can only be indexed by integers or slices, not strings.
for item in response:
for field in fields:
pprint(f"{field}: {item[field]}")
fields = ['id', 'name']
for item in response:
for field in fields:
pprint (f"{field}: {response[field]}")
It wanted the pprint indented to here but still have this error
Traceback (most recent call last):
File "/mnt/m2ssd/python/meraki_get_network_id.py", line 22, in <module>
pprint (f"{field}: {response[field]}")
~~~~~~~~^^^^^^^
TypeError: list indices must be integers or slices, not str
Don't change the value in RED.
fields = ['id', 'name']
for item in response:
for field in fields:
pprint(f"{field}: {item[field]}")
You the man thank you much appricated!
Try this starter code and change it any way you want. It displays your network name and ID.
Merakicode/DisplayNetworkStarterCode at main · jadexing/Merakicode · GitHub