简体   繁体   中英

Microsoft graph api list message count based on category color returns incorrect odata count when using PowerShell

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?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM