Code Response Comes Up in Browser, not so with Python Code

Solved
Jamieinbox
Getting noticed

Code Response Comes Up in Browser, not so with Python Code

I am not a coder-Jedi, help is appreciated.

 


I run this code, I get this error (also tried with BASE_URL = 'https://api.meraki.com/api/v1/'):
Http Error: 404 Client Error: Not Found for url: https://api.meraki.com/api/v1/networks/N_1111111111111111/wireless/clients/healthScores

Why? - The data comes up in a web browser just fine.

 

& Thank you.

 

#Code here#

import requests

BASE_URL = 'https://n1234.meraki.com/api/v1/'

def get_api_key():
return input("Enter your Meraki API key: ")

def get_organizations(api_key):
headers = {
'X-Cisco-Meraki-API-Key': api_key,
}
try:
response = requests.get(BASE_URL + 'organizations', headers=headers)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error occurred during API call: {e}")
return []

def display_organizations(organizations):
print("Organizations:")
for idx, org in enumerate(organizations, 1):
print(f"{idx}. {org['name']} (ID: {org['id']})")
print()

def get_networks(api_key, org_id):
headers = {
'X-Cisco-Meraki-API-Key': api_key,
}
try:
response = requests.get(BASE_URL + f'organizations/{org_id}/networks', headers=headers)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error occurred during API call: {e}")
return []

def display_networks(networks):
print("Networks:")
for idx, network in enumerate(networks, 1):
print(f"{idx}. {network['name']} (ID: {network['id']})")

def get_health_info(api_key, network_id):
headers = {
'X-Cisco-Meraki-API-Key': api_key,
'Content-Type': 'application/json', # Add Content-Type header
}
url = BASE_URL + f'networks/{network_id}/wireless/clients/healthScores'
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()

def main():
api_key = get_api_key()
organizations = get_organizations(api_key)

if organizations:
if len(organizations) == 1:
print(f"Only one organization available: {organizations[0]['name']} (ID: {organizations[0]['id']})")
selected_org_id = organizations[0]['id']
else:
display_organizations(organizations)
org_choice = int(input("Please enter the number of your organization: "))
selected_org_id = organizations[org_choice - 1]['id']

networks = get_networks(api_key, selected_org_id)
if networks:
display_networks(networks)

network_choice = int(input("Please enter the number of the network you want to check clients for: "))
selected_network_id = networks[network_choice - 1]['id']

health_info = get_health_info(api_key, selected_network_id)
print("Network Health Information:")
print(health_info)

if __name__ == "__main__":
main()

1 Accepted Solution

Sorry, I meant Early Access. Everything I find on documentation for that section is under the early access API https://developer.cisco.com/meraki/api-latest/get-network-wireless-devices-health-scores/

If you follow the menu on the left up it shows under Early Access. I can try to test with your code tomorrow and see if i get the same response without being signed up for Early Access

View solution in original post

8 Replies 8
PatWruk
Getting noticed

I'm not great with Python but when i attempt, i'm getting 404 on browser and postman, but I'm also not enrolled in EA. Are all of your networks enrolled in that? It could be something as simple as that. 

Thank you for the response.

EA, "Enterprise Agreement?" I think so, as we are licensed? I am able to do things like pull Networks, and the APs within networks in a nice little list. Just not getting anywhere with this pull. Or, when I do, the shell of the data is there- with MAC, but none of the score info. Thank you again for your thoughts.

Sorry, I meant Early Access. Everything I find on documentation for that section is under the early access API https://developer.cisco.com/meraki/api-latest/get-network-wireless-devices-health-scores/

If you follow the menu on the left up it shows under Early Access. I can try to test with your code tomorrow and see if i get the same response without being signed up for Early Access

Thank you! I have the code here, below, too- as all the formatting was dropped. I was able to pull stats on connections, and I am comparing the code now. If anything I think I am missing parameters, something with a Rest call. My hunch... but maybe I don't have EA...

jadexing/Merakicode: Code for Meraki Wi-Fi (github.com)
Here's the code I was able to get working (with some others posted)
Merakicode/LatencyStats at main · jadexing/Merakicode (github.com)

Thinking again, I was trying to crack this API before I saw anything posted on v3.

 

Jamieinbox
Getting noticed

Well arguing with myself. I can still pull this data up through a browser, just not into a terminal with code.

Jamieinbox_0-1691618275181.png

Still this... Doesn't make sense...

Jamieinbox_1-1691618369796.png

 

Hi @Jamieinbox , it sounds like there's a chance the API endpoint is part of the early access program. For more info we have a post in the sidebar at https://community.meraki.com/t5/Developers-APIs/bd-p/api with full details on the Early API Access program and what it means.

Ah... I thought because I was in API v 1 I was safe, further drilling in per pic below, I see it- and now know the significance. Thanks for assistance, was super confused as it was coming up in the browser.

Jamieinbox_0-1691619762906.png

Jamieinbox_1-1691619864656.png

 

 

Get notified when there are additional replies to this discussion.