Azure / Microsoft365R

R SDK for interacting with Microsoft 365 APIs
Other
308 stars 42 forks source link

Filter permission overrides `list_emails()` sorting #131

Closed mstackhouse closed 2 years ago

mstackhouse commented 2 years ago

From what I can gather, when I use a filter condition on an ms_outlook$list_emails() call, it overrides the by option and just sorts by ascending date.

x <- Microsoft365R::get_business_outlook()
#> Loading Microsoft Graph login for default tenant

y <- x$list_emails(n=5, by="received desc")
print(y[[1]]$properties$createdDateTime)
#> [1] "2022-08-30T19:52:47Z"
print(y[[5]]$properties$createdDateTime)
#> [1] "2022-08-30T18:37:17Z"

# The datetime of the 1st item should be later than the datetime of the 5th
lubridate::as_datetime(y[[1]]$properties$createdDateTime) >= lubridate::as_datetime(y[[5]]$properties$createdDateTime)
#> [1] TRUE

y <- x$list_emails(n=5,  by="received desc", filter="from/emailAddress/address eq 'Eli.Miller@atorusresearch.com'")
print(y[[1]]$properties$createdDateTime)
#> [1] "2020-03-16T13:25:51Z"
print(y[[5]]$properties$createdDateTime)
#> [1] "2020-03-19T12:24:29Z"

# The datetime of the 1st item should be later than the datetime of the 5th - but here it'snot
lubridate::as_datetime(y[[1]]$properties$createdDateTime) >= lubridate::as_datetime(y[[5]]$properties$createdDateTime)
#> [1] FALSE

Created on 2022-08-30 by the reprex package (v2.0.1)

mstackhouse commented 2 years ago

Just a note - I double checked and made sure I'm using the latest CRAN release.

hongooi73 commented 2 years ago

Unfortunately support for things like filtering and sorting is very patchy in the underlying Graph API. Some ops will work as intended, others will have only limited functionality, and others just don't work. From what I remember, many the email ops are in the latter 2 categories.

For now, the workaround is to pull everything that you need (filtering works here), and then do anything else client-side.

mstackhouse commented 2 years ago

Thanks for the quick response!!!

mstackhouse commented 2 years ago

If anyone else comes across this issue, here's how you'd make a filter condition for both an email and date of receipt:

# Get the outlook connection
x <- Microsoft365R::get_business_outlook()

# Use the `list_emails()` method with the OData expression
y <- x$list_emails(
   filter="from/emailAddress/address eq 'user@domain.com' and ReceivedDateTime ge 2022-08-01"
)

Help documentation is right here - but crafting the filter conditions takes some digging into Microsoft's documentation