08-30-2025 06:59 AM
I am attempting to write a script to pull events associated with non-meraki-vpns
import requests
def getNetworkAlerts(headers, networkId, startDate, endDate):
# Define the URL
url = (f"https://api.meraki.com/api/v1/networks/{networkId}/events")
params = {
"productType": "appliance",
"includedEventTypes[]": "non_meraki_vpn",
"startingAfter":startDate,
"endingBefore":endDate
}
# what is actually being sent to meraki dashboard
req = requests.Request('GET', url, headers=headers, params=params)
prepared_request = req.prepare()
print(f'The full url to be sent is: {prepared_request.url}')
# Below in red is what requests builds.
https://api.meraki.com/api/v1/networks/L_3895050727722058407/events?productType=appliance&includedEventTypes%5B%5D=non_meraki_vpn&startingAfter=2025-08-30+13%3A38%3A05.459567&endingBefore=2025-08-30+14%3A38%3A05.459567
# Send the GET request
response = requests.get(url, headers=headers, params=params) status code 400
However, if I build the url manually and don't use the keyword params
url = (f"https://api.meraki.com/api/v1/networks/{networkId}/events?productType=appliacnce&includeEventTypes[]=non_meraki_vpn&startingAfter=2025-08-30 13:52:56.146621&endingBefore=2025-08-30 14:52:56.146621')
I don't get the error. But I can't encode varaiables directly into the url. Research suggests you do this by using the keyword params in the requests library
Any more experienced coders out there got any advice please.
Solved! Go to Solution.
08-30-2025 08:08 AM
Also, this is not correct...
"startingAfter":startDate,
"endingBefore":endDate
These parameters are used by the pagination mechanism, you'll see that the documentation for the call says... "This parameter should not be defined by client applications."
https://developer.cisco.com/meraki/api-v1/get-network-events/
I just grab the results and filter out the ones that are out of the desired date range.
The endpoint can be fiddly to use, for instance check for a non-Null 'Message' element in the response, this may be used to signal that there are no matching events
08-30-2025 07:57 AM
You already posted a similar query https://community.meraki.com/t5/Developers-APIs/GET-networks-networkId-events-productType-appliance-amp/m-p/281786#M12897
If you look at my reply, you'll see that your usage...
"includedEventTypes[]": "non_meraki_vpn",
...is not correct.
08-30-2025 08:08 AM
Also, this is not correct...
"startingAfter":startDate,
"endingBefore":endDate
These parameters are used by the pagination mechanism, you'll see that the documentation for the call says... "This parameter should not be defined by client applications."
https://developer.cisco.com/meraki/api-v1/get-network-events/
I just grab the results and filter out the ones that are out of the desired date range.
The endpoint can be fiddly to use, for instance check for a non-Null 'Message' element in the response, this may be used to signal that there are no matching events
08-30-2025 08:14 AM
Would you like to try the Meraki Python SDK?
It will mask most of the lower level tweaks and help minimize mistakes.
08-30-2025 08:28 AM
I'm so used to people using the library that I didn't notice the OP was doing it the hard way.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide