cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to "get org id from org name" ?

SOLVED
Highlighted
Conversationalist

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

Accepted Solutions
Highlighted
Kind of a big deal

Re: How to "get org id from org name" ?

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
Kind of a big deal

Re: How to "get org id from org name" ?

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.

Highlighted
Conversationalist

Re: How to "get org id from org name" ?

thanks to @BrechtSchamp 

 

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

 

Highlighted
Kind of a big deal

Re: How to "get org id from org name" ?

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

Highlighted
Conversationalist

Re: How to "get org id from org name" ?

Hey Phil, 

 

this is exactly what I was looking for. 

This code eliminates a lot of work in error avoiding. 

 

Thank you very much. 

 

Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.