Multiple API calls using data from 1st call...

sambo
Getting noticed

Multiple API calls using data from 1st call...

Hi,

I'm using this API call using python:

import requests
import json

url = "https://api.meraki.com/api/v1/organizations"

payload={}
headers = {
'X-Cisco-Meraki-API-Key': 'xxxxxxxxxx

response = requests.request("GET", url, headers=headers, data=payload)

r = json.loads(response.text)


for organizations in r:
print(organizations['name'] + ' ' + organizations['id'])

 

The output is what I'm looking for.

What I need to do now is to be able to use the organization id to then call all the networks in each org:

eg.....

API CALL 1....url = "https://api.meraki.com/api/v1/organizations"

(THIS WILL PRINT OUT ALL ORGS I HAVE ACCESS TO)

Then use these ID's in the next calls until no ID's are left...

 
If anyone has any advise or a script they have used that would be great.
Thanks
Sam
 
 

 

6 Replies 6
PhilipDAth
Kind of a big deal
Kind of a big deal

If you use the Meraki Dashboard API library:

https://developer.cisco.com/meraki/api-v1/ 

 

Then you can use some code like this:

 

	# Search for the org
	orgs = dashboard.organizations.getOrganizations()
	for org in orgs:
		if org['name'] == orgName:
			orgId=org['id']
			break;

	if orgId == None:
		print("Invalid organization name supplied: "+orgName)			
		exit(-1)

 

If I run this after the 1st API call it fails:

 

orgs = dashboard.organizations.getOrganizations()
NameError: name 'dashboard' is not defined

 

I'm just not sure how to link the API query with this and then use it for the 2nd query.

 

Thanks

Sam

 

Edgar-VO
Building a reputation

Hi,
 
First create a session like :
 
dashboard       = meraki.DashboardAPI(api_key)
 
my_org = dashboard.organizations.getOrganizations()

 

for org in my_org:
        org_id = org['id']
        print(org['name'])
sambo
Getting noticed

If this is the script that calls the ORG names:

#SCRIPT THAT CALLS THE ORGS THEN ONLY PRINTS THE ORG NAME ONLY
import requests
import json

url = "https://api.meraki.com/api/v1/organizations"

payload={}
headers = {
'X-Cisco-Meraki-API-Key': 'xxxx'
}

response = requests.request("GET", url, headers=headers, data=payload)


r = json.loads(response.text)

for organizations in r:
print(organizations['name'])

 

Where does the create session from below get inserted?

First create a session like :
 
dashboard       = meraki.DashboardAPI(api_key)
 
my_org = dashboard.organizations.getOrganizations()

 

for org in my_org:
        org_id = org['id']
        print(org['name'])

 

John-K
Meraki Employee
Meraki Employee

@sambo the suggestions above are correct and rely on installing and using the Python SDK.

 

Please read the Python SDK readme for instructions: https://github.com/meraki/dashboard-api-python

sambo
Getting noticed

I'm reading and learning now, Thanks!

Sam

Get notified when there are additional replies to this discussion.
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.