Was trying to get call records via getPstnCalls
(see docs). You need to specify a start and end date so by default the query is like this:
1 |
GET https://graph.microsoft.com/v1.0/communications/callRecords/getPstnCalls(fromDateTime=2019-11-01,toDateTime=2019-12-01) |
Or using PowerShell (below it’s from 1st Jan to 1st March 2023):
1 |
Invoke-MgGraphRequest -Uri 'https://graph.microsoft.com/v1.0/communications/callRecords/getPstnCalls(fromDateTime=2023-01-01,toDateTime=2023-03-01) |
But can I filter these? For example, based on usageCountryCode
. Yes you can:
1 |
Invoke-MgGraphRequest -Uri 'https://graph.microsoft.com/v1.0/communications/callRecords/getPstnCalls(fromDateTime=2023-01-01,toDateTime=2023-03-01)?$filter=usageCountryCode eq ''US''' |
Notice the double single quotes around the country code. That’s important. Ditto for other fields like UPN:
1 |
Invoke-MgGraphRequest -Uri 'https://graph.microsoft.com/v1.0/communications/callRecords/getPstnCalls(fromDateTime=2023-01-01,toDateTime=2023-03-01)?$filter=userDisplayName eq ''abc@def.com''' |
Remember this only gives you part of the results. You need to keep looping. Something like this (where I add the results to an array):
1 2 3 4 5 6 7 8 9 10 11 |
$resultsArray = [System.Collections.Generic.List[object]]@() do { $results = Invoke-MgGraphRequest -Uri $queryURL foreach ($entry in $results.Value) { $resultsArray.Add($entry) } $queryURL = $results.'@odata.nextLink' } until ($results.'@odata.nextLink'.Length -eq 0) |
Update: This doesn’t actually work. Doesn’t return an error, so you think it is filtering, but in reality it doesn’t.