Powershell - getNetworkEvents - specifying multiple event types (includedEventTypes)

kdc
Here to help

Powershell - getNetworkEvents - specifying multiple event types (includedEventTypes)

Hello,

 

I'm trying to get VPN connect/disconnect events using Powershell to access the API.  I can access all events, but I am having trouble filtering the events based on includedEventTypes.

 

Pretty simple code:

### start code ###

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$headers = @{
'Content-Type' = 'application/json'
"X-Cisco-Meraki-API-Key" = $APIKey
}

 

$Body = @{
"productType" = "appliance"
#"perPage" = "1000"

}

 

$Events = @()

 

$MerakiEvents = Invoke-RestMethod -Method Get -Uri $NetworkC10uri -Headers $headers -Body $Body

 

foreach ($event in $MerakiEvents.events)
{

$EventInfo = New-Object System.Object
$EventInfo | Add-Member -type NoteProperty -name occurredAt -Value $Event.occurredAt
$EventInfo | Add-Member -type NoteProperty -name Type -Value $Event.type
$EventInfo | Add-Member -type NoteProperty -name clientId -Value $Event.clientId
#$EventInfo | Add-Member -type NoteProperty -name Mac -Value $Event.mac
$Events += $EventInfo
}

$Events

 

### end code ###

 

 

The code above works great, but I can't figure out how to send a "collection" in the $body for includedEventTypes.

 

I want to filter by 'client_vpn_connect','client_vpn_disconnect'.

 

I have tried tons of formats, and can't find anything that works.

 

 

None of these examples work:

$Body = @{
"productType" = "appliance"
#"perPage" = "1000"
#"includedEventTypes" = @('client_vpn_connect', 'client_vpn_disconnect')
#"includedEventTypes" = 'client_vpn_connect','client_vpn_disconnect'
#includedEventTypes[] = 'client_vpn_connect','client_vpn_disconnect'
#'includedEventTypes[0]' = 'client_vpn_connect'
#"includedEventTypes" = $EventFilter
}

 

Any help would be greatly appreciated.  Thanks.

 

 

4 REPLIES 4
chengineer
Meraki Alumni (Retired)
Meraki Alumni (Retired)

The last messages in this thread might be helpful? https://community.meraki.com/t5/Developers-APIs/Air-Marshal-API-calls-not-all-the-expected-events-ar...

Solutions Architect @ Cisco Meraki | API & Developer Ecosystem

Thanks, I looked at that thread before posting my message.  That is the kind of information I am looking for, but it is Python not Powershell.  Ultimately the Python and Powershell deal with parameters a little differently (Python doesn't meet my requirements at this time).

 

I managed to get a little further, but I am still stuck.

 

I figured out that I need to include the square brackets in the name of the key, and I can get it working with a single value ('includedEventTypes[]' = 'client_vpn_connect'):

 

$Body = @{
'productType' = 'appliance'
'perPage' = $perPage
'includedEventTypes[]' = 'client_vpn_connect'

}

 

Now I am stuck on how to add a second value into that key.

 

These don't work.

 

'includedEventTypes[]' = 'client_vpn_connect','client_vpn_disconnect'

'includedEventTypes[]' = @('client_vpn_connect','client_vpn_disconnect')

 

#This one seems like a good idea, but I can't have two identical keys in the same hash table.

'includedEventTypes[]' = 'client_vpn_connect'

'includedEventTypes[]' = 'client_vpn_disconnect'

 

chengineer
Meraki Alumni (Retired)
Meraki Alumni (Retired)

Ah OK, I think I've figured out the issue, which is that these query parameters should be passed in the resource as opposed to the body. If you modify the URI to be something like the following, it should work:

 

$networkUri = 'https://api.meraki.com/api/v0/networks/L_123456789/events?productType=appliance&perPage=30&includedEventTypes[]=client_vpn_connect&includedEventTypes[]=client_vpn_disconnect'

 

 

Solutions Architect @ Cisco Meraki | API & Developer Ecosystem

Yeah, I can see how setting it in the resource as part of the URI is the proper way to do it.  However, I still want something a little more automated that builds that part of the URI from an array.

 

I have a couple of ideas, but I think HttpValueCollection is the most promising.  Create an HttpValueCollection and use System.UriBuilder to put together all of the different parts of the URI.

 

https://stackoverflow.com/questions/32442777/how-to-use-get-method-of-invoke-webrequest-to-build-a-q...

 

I don't have time to try and code this right now.  Hopefully I'll be able to circle back to it in a couple of weeks.

Get notified when there are additional replies to this discussion.