12-18-2023 11:45 AM
For example: I'm trying to get just the Organization name:
https://api.meraki.com/api/v1/organizations/{organizationId}?fields=name
Or find out the organizationId for a company called "CompanyName"
https://api.meraki.com/api/v1/organizations/{organizationId}?fields=id&name="CompanyName"
I have tried many different variations of the above, and search in the forums to no avail.
Other API's I've worked with have a way to pass conditions into the request and only get back the single field you need. That would sure save a bunch of parsing when the payload returns to my console.
Thaks in advance for the help.
12-18-2023 12:01 PM
Natively (if I'm not mistaken) you won't be able to do it this way. Today, to extract the information the way I need it, I am using the following code.
import requests
import json
# Make the API request
response = requests.get('https://api.meraki.com/api/v1/organizations/{organizationId}')
# Convert the response to JSON
data = response.json()
# Extract the field you need
org_name = data['name']
I hope it helps.
12-18-2023 12:02 PM
The current API returns what it likes, for a given API call it can also vary depending on context. There's no way to limit which field(s) are returned.
12-18-2023 12:29 PM
Thank you for the quick responses. I had hoped I was just missing something, 😉
I will carry on parsing and extracting.
Have a great day!
12-19-2023 12:22 PM
Here is an example in Python of getting an org and network ID by searching on the name using the Meraki Python SDK.
# This function retrieves the netId
def getNetId(orgName,netName):
orgId=None
netId=None
# Search for the org
for org in dashboard.organizations.getOrganizations():
if org['name'] == orgName:
orgId=org['id']
break;
if orgId == None:
print("Invalid organization name supplied: "+orgName)
exit(-1)
# Search for the network
for net in dashboard.organizations.getOrganizationNetworks(orgId):
if net['name'] == netName:
netId=net['id']
break;
# If no network, search for a template
if netId == None:
for net in dashboard.organizations.getOrganizationConfigTemplates(orgId):
if net['name'] == netName:
netId=net['id']
break;
# Nothing found matching at all
if netId == None:
print("Invalid network name supplied: "+netName)
exit(-1)
return netId
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