Getorganizationdevices not filtering by network id

primeria24
Comes here often

Getorganizationdevices not filtering by network id

Hi, 

im Trying to filter devices out of the org based on a network id but the output keeps printing the whole org. i have tried different variations to see if it will filter but i cant get it to work. has anyone else experienced this? i can get the devices of the network when i run it through postman but when i use the meraki python sdk it outputs the whole org instead of devices from the network id. 

 

i have tried:

network_ids = ['**********']  
org_id = "**************"

try:
response = dashboard.organizations.getOrganizationDevices(
org_id,
params={
'networkIds[]': [network_ids],
}
)
print(response)
except ValueError as ve:
print(f"Value Error: {ve}")

 

network_ids = '**********'
org_id = "**************"

try:
response = dashboard.organizations.getOrganizationDevices(
org_id,
params={
'networkIds[]': [network_ids],
}
)
print(response)
except ValueError as ve:
print(f"Value Error: {ve}")

----------------------------------------------------------------------------------------

network_ids = ['**********']
org_id = "**************"

try:
response = dashboard.organizations.getOrganizationDevices(
org_id,network_ids
)
print(response)
except ValueError as ve:
print(f"Value Error: {ve}")

--------------------------------------------------------------------------------------

network_ids = ['**********']
org_id = "**************"

try:
response = dashboard.organizations.getOrganizationDevices(
org_id,
params={
'networkIds': [network_ids],
}
)
print(response)
except ValueError as ve:
print(f"Value Error: {ve}")

-----------------------------------------------------------------------------------------------

network_ids = ['**********']
org_id = "**************"

try:
response = dashboard.organizations.getOrganizationDevices(
org_id,network_id
)
print(response)
except ValueError as ve:
print(f"Value Error: {ve}")

 

 

Any suggestions appreciated.

6 Replies 6
MartinLL
Building a reputation

Try to create the query variable before you pass it in the requests function.

 

Like this for example. 

 

params = {'networkID': '12345'}

 

Then

response = dashboard.organizations.getOrganizationDevices(params=params)

 

MLL
primeria24
Comes here often

hello martin, 

This doesnt work. i believe there may be something going on with this function in the meraki python SDK. it fails to append the query paramters to the end of the api call URL. 

Thanks,

sungod
Kind of a big deal

networkIds is keyword argument, try...

 

response = dashboard.organizations.getOrganizationDevices(
org_id, networkIds=['id1'])

 

primeria24
Comes here often

Hello sungod, 

This doesnt work. 

Thanks,

sungod
Kind of a big deal

I just tested, it works fine for me.

 

Here's my test script...

 

import os
import sys

import meraki.aio
import asyncio

ORG_ID = os.environ.get("PARA0")

API_KEY = os.environ.get("PARA1")

async def main():
    # Instantiate a Meraki dashboard API session
    async with meraki.aio.AsyncDashboardAPI(
        api_key=API_KEY,
        base_url='https://api.meraki.com/api/v1/',
        print_console=False,
        output_log=False,
        suppress_logging=True,
        wait_on_rate_limit=True,
        maximum_retries=100,
        maximum_concurrent_requests=5

    ) as aiomeraki:
    

        networks = await aiomeraki.organizations.getOrganizationNetworks(ORG_ID, perPage=1000, total_pages="all")
        
        for net in networks:
            print(f'{net["id"]} {net["name"]}')

        devices = await aiomeraki.organizations.getOrganizationDevices(ORG_ID, networkIds=["put the ID here"], perPage=1000, total_pages="all")

        for d in devices:
            print(d)
                        
        sys.exit(0)

if __name__ == '__main__':
    asyncio.run(main())

 

 

Jamieinbox
Building a reputation

Hi, I have code that does this. Please feel free to use. It only pulls up APs, but it can be changed for switches and other. Also on this page, I have something called, "ListNetworkStarterCode," that will help you take the org and list the network. 
Merakicode/APs&Ser_PerNetwork at main · jadexing/Merakicode

I have a lot on github for Meraki. Please help yourself. I've been working at bettering old code and putting a good description of which APIs are referenced and what the code does.

Get notified when there are additional replies to this discussion.