Subject
Graph Api to filter email messages from a given folder such as inbox,etc and filter them on 'from' and 'subject' clause and finally order the results by DESCENDING order of 'receivedDateTime'
Our aim is to fetch emails from outlook with below criteria:
Fetch emails from a given folder such as 'INBOX', 'SENT', etc
Fetch emails with a filter clause on 'from' and 'subject'
Fetch the results in DESCENDING sorted order of 'receivedDateTime' (The most recent receivedDateTime should be at the top )
So we tried with all your concerned graph Apis but each of them seems to be have their own limitations.
We tried with the below three Apis:
a.) FILTER parameter api
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$select=id,receivedDateTime,subject,from&$filter=from/emailAddress/address eq 'nitesh.kumar@franconnect.com'
However the search results are in the ASCENDING order of 'receivedDateTime' whereas we need it in DESCENDING order of 'receivedDateTime'.
We even added an '$orderBy' query parameter to the the above URL but to no avail:
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$select=id,receivedDateTime,subject,from&$filter=from/emailAddress/address eq 'nitesh.kumar@franconnect.com'&$orderBy=receivedDateTime DESC
However the response says
{
"error": {
"code": "InefficientFilter",
"message": "The restriction or sort order is too complex for this operation.",
"innerError": {
"date": "2021-12-08T10:29:39",
"request-id": "fc09dfbb-76b9-4c86-8b25-babd66594751",
"client-request-id": "75af9f90-9e78-14c8-72af-316ccee83b71"
}
}
}
It looks like ‘Order By’ clause is not supported by your $filter api.
Question : Can you please elaborate on how to order by ‘receivedDateTime’ ?
b.) To get past the above limitation we experimented with your GET search api.
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$search="from:tribhuwan.negi@franconnect.com"&$select=id,receivedDateTime,subject,from&$top=300
Though this api fetches results in the DESCENDING order of 'receivedDateTime' but However there seems to be a limitation on the maximum number of records fetched by it.
The above search Api FETCHES ONLY A MAXIMUM OF 250 RECORDS !!
Also it does not support a $skip parameter ( Error message: "The query parameter '$skip' is not supported with '$search' )
Question: Please elaborate on how can I get records beyond 250 ?
c.) We also tried your generic search API
POST https://graph.microsoft.com/v1.0/search/query
{
"requests": [
{
"entityTypes": [
"message"
],
"query": {
"queryString": "from:tribhuwan.negi@franconnect.com"
},
"from": 0,
"size": 25
}
]
}
Even this API has it own limitations.
The above Api DOES NOT fetch results from a 'GIVEN FOLDER'.
Rather the search results are spread across all folders.
Question: How can I get search results within a given folder ?
As you can see that all the above APIs do not satisfy our business criteria, namely :
Fetch emails from a given folder such as 'INBOX', 'SENT', etc
Fetch emails with a filter clause on 'from' and 'subject'
Fetch the results in DESCENDING sorted order of 'receivedDateTime' (The most recent receivedDateTime should be at the top )
We are writing to you to help us point if we have missed anything in our analysis.
Also please point to us the right API to solve our problem.