How to "get org id from org name" ?

Solved
MartinSeitz
Here to help

How to "get org id from org name" ?

Hello Meraki & API fans, 

 

I have discovered a problem that I wasn't able to solve today. 

 

I am sure you all know the following code. 

 

api_key = '093b24e85df15a3e66f1fc359f4c48493eaa1b73' #sandbox
import meraki
m = meraki.DashboardAPI(api_key)
orgs = m.organizations.getOrganizations()
print(orgs) 

The result in my case is:

 

[{'id': '537758', 'name': 'Meraki Launchpad🚀', 'url': 'https://n149.meraki.com/o/d029Cc/manage/organization/overview', 'samlConsumerUrl': 'https://n149.meraki.com/saml/login/d029Cc/rtFn7bJtIRna', 'samlConsumerUrls': ['https://n149.meraki.com/saml/login/d029Cc/rtFn7bJtIRna']}, {'id': '549236', 'name': 'DevNet Sandbox', 'url': 'https://n149.meraki.com/o/-t35Mb/manage/organization/overview'}]

 

My goal is to have python code that delivered the organization ID to a corresponding organization name. 

Like, give me the ID from the Organisation with the name Meraki Launchpad🚀.

The ID is 537758

 

I have searched the whole day was not able how to transform the data to get this information. 

 

I need this because I want to create a new organization with the API and then the same script should return the Id of the newly created organization so that I can use that information for the next operations or following scripts. 

But I don't want to request all Orgs and then copy past the key by hand this should come from the script. 

 

If You do think I am on the wrong way with the problem above feel free to let me know. 

 

Thanks for your replies. 

 

1 Accepted Solution
PhilipDAth
Kind of a big deal
Kind of a big deal

I use a function like this:

 

def get_org_id(meraki,orgName):
	result = meraki.organizations.get_organizations()
	for row in result:
		if row['name'] == orgName:
			return row['id']

	raise ValueError('The organization name does not exist')

View solution in original post

4 Replies 4
BrechtSchamp
Kind of a big deal

You'll have to have your script loop over the results of the getOrganizations() call, and compare each name against the one you need. Since it will be doing that offline it should be pretty quick.

MartinSeitz
Here to help

thanks to @BrechtSchamp 

 

with your idea of comparison I was able to develop a solution for my problem. 

 

PhilipDAth
Kind of a big deal
Kind of a big deal

I use a function like this:

 

def get_org_id(meraki,orgName):
	result = meraki.organizations.get_organizations()
	for row in result:
		if row['name'] == orgName:
			return row['id']

	raise ValueError('The organization name does not exist')
MartinSeitz
Here to help

Hey Phil, 

 

this is exactly what I was looking for. 

This code eliminates a lot of work in error avoiding. 

 

Thank you very much. 

 

Get notified when there are additional replies to this discussion.