Is it possible to search for messages with a matching substring in body and also a matching date? - microsoft-graph-api

I would like to, in a single request, get a list of messages filtered by date and by content in the body (if it's possible, of course).
I'm perfectly able to receive an ok response (200) from the following endpoint:
https://graph.microsoft.com/v1.0/users/user#company.com/messages?search="body:substring"
However, this gives me a broad response, since I'm interested only in cases between a specific week. Also, it's impossible to use a filter parameter along with the search one.
Then, in regard to the date filter, I could use:
https://graph.microsoft.com/v1.0/users/user#company.com/messages?$filter=(sentDateTime ge 2000-01-01) and (sentDateTime le 2100-01-01)
The problem is: I cannot filter the body as well, since I receive an error 400 - 'Bad Request: Invalid filter clause':
https://graph.microsoft.com/v1.0/users/user#company.com/messages?$filter=contains(body, substring)
Right now, my work around is: I request all the messages from user#company.com regarding a specific week, and after receiving that response, I locally filter the body in my machine. This works, but is not as fast as a compound request.

You can include specific a date restriction within your KQL Search eg
https://graph.microsoft.com/v1.0/me/messages?$search="(sent>=2019-01-01 AND sent<=2019-02-01) AND (body:asx)"
That should yield better performance then a filter

Related

ADO API: Builds-List incomplete list

I'm calling this API method:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-6.0#response
My API url (with placeholder names):
https://dev.azure.com/MyOrgName/MyProjName/_apis/build/builds?api-version=6.1-preview.6
The results are mostly appropriate, except I get a filtered list of builds, and I can't seem to get all the builds I want. In particular, builds from several pipelines are simply missing, and I can't find any way to include them. There's no discernable reason why some builds are included, and some are not.
The filter options describe ways I could reduce it more, but that's not my goal. I want to retrieve builds which I am otherwise not getting. And I don't know what option that I don't know about which will get me the results I care about.
As you have already noticed, there is a maximum number of the objects that can be listed on the response body of each API call. Normally, if the objects you want to list are too many, they will be returned in multiple pages.
In the response body of each call, generally there is a parameter 'continuationToken' (see here). You can access the next response page via calling the API with this parameter.
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds?continuationToken={continuationToken}&api-version=6.1-preview.6
For example:
the first call returns the list in the first page;
then run the second call with the parameter 'continuationToken' returned in the response of the first call to get the second page;
then get the third page using the 'continuationToken' returned in the second response;
. . .
until the last page.
If you want to traverse all the pages, you may need to call the API in a loop.

Get last page of GitHub Search Api result in iOS

I'm making a new iOS (swift) app to test some concepts, and I'm using the GitHub Serach API to retrieve a list of filtered repositories.
The request is working fine so far, but I'm having trouble understanding the pagination process and how to know I reached the end of the results.
For what I saw, the Search API returns a maximum of 1k results, broke in pages of 100 maximum results. But the field in the returned json with the total count shows way more available results (I imagine that it shows the total repositories that satisfy the query and not the maximum available for return in the API).
The only way I found so far to obtain information about the pages (and the pagination process) in GitHub Documentation comes in the header of the response, like:
Status: 200 OK
Link: <https://api.github.com/resource?page=2>; rel="next",
<https://api.github.com/resource?page=5>; rel="last"
X-RateLimit-Limit: 20
X-RateLimit-Remaining: 19
Anyone can suggest the best approach to detect the end of the pages in this case?
Should I try to parse the information from the header or infer it somehow based on the returned json? I even got the "Link" header value but don't know how to parse it.

How to fix MS Graph message body search?

Using graph explorer to execute the following message search by subject works as expected:
https://graph.microsoft.com/v1.0/me/messages?$search=%22subject%3Agoogle.com%3A443%2Fsearch%3Fq%3Da%2Btest*%22
However, this message search by body fails. The only difference between this and the previous search is that subject is replaced with body:
https://graph.microsoft.com/v1.0/me/messages?$search=%22body%3Agoogle.com%3A443%2Fsearch%3Fq%3Da%2Btest*%22
The error that I receive for the second search is "An internal server error occurred. The operation failed., Too few pops in query tree".
This search used to work. How do I fix it?
This is a 500 error - you won't make this work. I'll report this as an error. The error appears to be with the second colon in the search string.
$search="body:google.com:443/search?q=a+test*" - this 500s
$search="body:google.com443/search?q=a+test*" - this 200s
Conjecture
I suspect that the search feature now supports multiple fields as the following query works as expected:
https://graph.microsoft.com/v1.0/me/messages?$search="body:Minerva subject:pilot"
This would break your query as it appears that the colon is only considered for specifying the field to search on.
Potential workaround
You could break your query string into multiple parts like this:
https://graph.microsoft.com/v1.0/me/messages?$search="body:google.com AND body:443/search?q=a+test*"
It is not sufficient but may work for your scenario.

Missing or Invalid Url Parameter with Twitter API

I am using the Twitter API's Search Tweets endpoint (https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets) to search for tweets on a particular topic. My application is written in Java and uses Twitter4j. I follow the guidelines (i.e. no more than 180 calls per minute and no more than 500 characters per query) however I do have a test case that has 50 word exclusions (so the total character count is 397). My test program also runs 100 such searches in rapid succession though, like I said, I observe the rate limits strictly.
The odd behavior I'm seeing is that the test runs fine and gets results initially, but after an arbitrary period of time, I start getting the following error:
Message: Missing or invalid url parameter. 403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - Missing or invalid url parameter.
code - 195
The error message confuses me because I'm not trying to perform any of the update actions listed in the link provided. I'm just searching tweets. I'm also not sure what "missing or invalid url parameter" means. Is a query parameter missing from my request? The only required parameter is the query itself which I am definitely passing. The url is definitely correct unless Twitter4j is generating incorrect urls. So what does this message mean?
When I stop and restart the search (i.e. the max_id and since_id values get reset to -1, the searches start working again...for a while. As far as I know, nothing else about the search changes when it is restarted. Just those two ids.

Select fields on Microsoft Graph list of Messages

I'm using Microsoft Graph to get a list of messages for a user.
I'm using the following URL
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages
One important thing that is returned by this is the meetingMessageType when the message revolves around a meeting request.
I would also like to get the uniqueBody of the message. However, that's not provided by default. One needs to specifically ask for that field. I can do that by adding ?$select=uniqueBody to the URL.
However, that now means that I need to add the rest of the fields I want to the $select query parameter. That's not a big deal until I run into meetingMessageType. Microsoft Graph returns:
Could not find a property named 'meetingMessageType' on type 'Microsoft.OutlookServices.Message'.
What can I do to ensure I get both uniqueBody and meetingMessageType?
Try this:
$select=uniqueBody, microsoft.graph.eventMessage/meetingMessageType
Yogesh's answer is close but will result in a Only one level select is supported error.
As long as you don't care about the value of meetingMessageType, you can use this select:
$select=microsoft.graph.eventMessage, uniqueBody
You'll note that the results no longer include meetingMessageType as a property. The list however is limited to only those messages that are eventMessage, effectively giving you a result set filtered to only show meeting requests.

Resources