404 Error when trying to search for networks inside my Organization.

Justin5
New here

404 Error when trying to search for networks inside my Organization.

 

The code I am using is bellow.  I'm just starting off with some API stuff.  When logging into Meraki we have one Organization and a bunch of other networks under that.  But when searching for the networks it prints the organization correct but for the networks I am getting a "HTTPError: 404 Client Error: Not Found for url: https://api.meraki.com/api/v1/organzations/ID/networks.

 

Any idea what is wrong here?

 

 

 

 

 

 

import requests

api_key = input("Enter a Key ")

def meraki_get(resource😞
   
   
    headers = {
        "Content": "application/json",
        "X-Cisco-Meraki-API-Key": api_key
    }

    get_resp = requests.get(f"{api_path}/{resource}", headers=headers)

    get_resp.raise_for_status()
    return get_resp.json()

def main():
    orgs = meraki_get("organizations")
    print ("Organization Discovered")

    Test_id = 0
    print(Test_id)
    for org in orgs:
        print(f"ID: {org['id']:<6} Name: {org['name']}")
        if "Test" in org ["name"]:
            Test_id = org["id"]
       
    if Test_id:
        networks = meraki_get(f"organzations/{Test_id}/networks")
        print(f"\nNetworks seen for AMPI org ID {Test_id}")

    Test_network = ""
    for network in networks:
        print(f"Network ID: {network['id']} Name: {network ['name']}")
             

if __name__ == "__main__":
    main()
2 Replies 2
Jamieinbox
Getting noticed

I had that error at one point. I use this for my starter code. It displays and numbers networks.

Merakicode/DisplayNetworkStarterCode at main · jadexing/Merakicode (github.com)

sungod
Head in the Cloud

If you insert an print to show the value of Test_id before the get, is it showing the expected org ID ?

 

I ask, because this code...

 

    Test_id = 0
    print(Test_id)
    for org in orgs:
        print(f"ID: {org['id']:<6} Name: {org['name']}")
        if "Test" in org ["name"]:
            Test_id = org["id"]
 
...will leave Test_id = 0 if the condition is never true, giving the 404 error.
Get notified when there are additional replies to this discussion.