Hi guys, since you're doing this in Python, you may want to return the response.text error message to troubleshoot. In this case, I believe the 400 error you're seeing could be either "productType is required" or "'includedEventTypes'" must be an array". The former, which I believe you know this by now, is that for combined networks, you need to specify the productType for this endpoint to work.
For the latter error, if you're trying to filter for specific event types, that needs to be an array/list, so the way to do that using params within requests.get is to specify it as an array, namely 'includedEventTypes[]' as the key for your params dictionary.
Here's an example of a function that will do what you're looking for in Python using the requests library.
# https://api.meraki.com/api_docs#list-the-events-for-the-network
def get_event_log(api_key, networkId, productType=None, includedEventTypes=None, excludedEventTypes=None, deviceMac=None,
deviceSerial=None, deviceName=None, clientIp=None, clientMac=None, clientName=None, smDeviceMac=None,
smDeviceName=None, perPage=None, startingAfter=None, endingBefore=None, retries=5):
resource = f'https://api.meraki.com/api/v0/networks/{networkId}/events'
parameters = ['productType', 'deviceMac', 'deviceSerial', 'deviceName', 'clientIp', 'clientMac', 'clientName',
'smDeviceMac', 'smDeviceName', 'perPage', 'startingAfter', 'endingBefore']
params = {key: value for (key, value) in locals().items() if key in parameters and value != None}
if includedEventTypes:
params['includedEventTypes[]'] = locals()['includedEventTypes']
elif excludedEventTypes:
params['excludedEventTypes[]'] = locals()['excludedEventTypes']
while retries > 0:
response = requests.get(resource, headers={'X-Cisco-Meraki-API-Key': api_key, 'Content-Type': 'application/json'}, params=params)
if response.ok:
print('success')
return response.json()
elif response.status_code == 429:
wait = int(response.headers['Retry-After'])
print(f'retrying in {wait} seconds')
time.sleep(wait)
retries -= 1
else:
message = response.text
print(f'failed with error {response.status_code}, {message}')
return None
Solutions Architect @ Cisco Meraki | API & Developer Ecosystem