Failed to fetch port configurations for switch with serial ****-*****-****. Status code: 404
No port data available.
I know the key and other parameters are correct because I am able to fetch other information like Network IDs from Org
Any help is appreciated.
import requests
import csv
# Function to get port configurations from a Meraki switch
def get_port_config(api_key, org_id, serial) :
headers = {"X-Cisco-Meraki-API-Key": api_key, "Content-Type": "application/json"}
response = requests.get(url, headers=headers)
# Check if the response is successful (status code 200)
if response.status_code == 200:
return response.json()
else:
print(
f"Failed to fetch port configurations for switch with serial {serial}. Status code: {response.status_code}"
)
return None
# Function to write port configurations to a CSV file
def write_to_csv(ports_data, filename) :
if ports_data is None:
print("No port data available.")
return
with open(filename, "w", newline="") as csvfile:
fieldnames = ["Port", "Enabled", "VLAN", "Type"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for port in ports_data:
writer.writerow(
{
"Port": port.get("number", ""),
"Enabled": port.get("enabled", ""),
"VLAN": port.get("vlan", ""),
"Type": port.get("type", ""),
}
)
def main():
api_key = "****"
org_id = "****"
switch_serials = [
"****-****-****",
"****-****-****",
] # Add your switch serials here
output_filename = "port_configurations.csv"
for serial in switch_serials:
ports_data = get_port_config(api_key, org_id, serial)
write_to_csv(ports_data, f"{serial}_{output_filename}")
if __name__ == "__main__":
main()