cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3142
Views
0
Helpful
4
Replies

return specified fields only with api call

blshaw32
Community Member

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.

4 Replies 4

aleabrahao
Meraki Community All-Star
Meraki Community All-Star

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.

I am not a Cisco employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.

sungod
Level 11
Level 11

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.

blshaw32
Community Member

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!

Philip D'Ath
Meraki Community All-Star
Meraki Community All-Star

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