cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3774
Views
12
Helpful
4
Replies

API Query parameter handling

russell.sage
Level 7
Level 7
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.
 
1 Accepted Solution

Accepted Solutions

sungod
Level 11
Level 11

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

View solution in original post

4 Replies 4

sungod
Level 11
Level 11

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.

sungod
Level 11
Level 11

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

obrigg
Meraki Employee All-Star
Meraki Employee All-Star

Would you like to try the Meraki Python SDK?

It will mask most of the lower level tweaks and help minimize mistakes.

I'm so used to people using the library that I didn't notice the OP was doing it the hard way.