Reputation: 328
I'm working on a PowerShell script to retrieve message count based on category color applied to the message. I'm using microsoft graph api to achieve this. When i use microsoft online graph api developer tool to test the request endpoint, i get a correct value for odata.count
. However when i query the same endpoint uri using powershell i get incorrect value for odata.count(here the endpoint returns total count for all messages in that particular folder).
Below is the snips for the tests.
Querying the endpoint using online microsoft graph api developer tool
Response from the tool(This is the true value for all messages with category green)
Request and response value when using powershell to query the same graph uri(This is incorrect value)
Below is the request call endpoint
$accessToken = "accesstokenhere"
$mail_user = "emailhere"
$blue_uri = "https://graph.microsoft.com/v1.0/users/$mail_user/mailFolders/inbox/messages?$filter=categories/any(a:a+eq+'Green+category')&count=true"
$blue_resp = Invoke-RestMethod -Method get -Uri $blue_uri -ContentType "application/json" -Headers @{Authorization=("bearer {0}" -f $accessToken)}
$blue_resp
Have assigned all microsoft graph api mail and mailboxsettings
permissions in the azure ad oauth app that i'm using to get the accesstoken.
What could be wrong?
Upvotes: 1
Views: 732
Reputation: 20768
The PowerShell expects that $filter
is a variable. You need to use the backtick escape character ` before $filter
$blue_uri = "https://graph.microsoft.com/v1.0/users/$mail_user/mailFolders/inbox/messages?`$filter=categories/any(a:a+eq+'Green+category')&count=true"
Upvotes: 1