$orderby event start time in MS graph explorer - microsoft-graph-api

I'm currently running this query successfully in graph explorer:
https://graph.microsoft.com/v1.0/groups/07805...9e84/events
However, I want to sort and filter (I'll save the latter for another question).
The link above returns an object which contains the following:
"start": {
"dateTime": "2022-08-19T15:00:00.0000000",
"timeZone": "UTC"
},
I've tried the following, with the accompanying results:
https://graph.microsoft.com/v1.0/groups/0780...9e84/events?$orderby=start desc
"The $orderby expression must evaluate to a single value of primitive type.",
https://graph.microsoft.com/v1.0/groups/0780...9e84/events?$orderby=start.dateTime desc
The child type 'start.dateTime' in a cast was not an entity type. Casts can only be performed on entity types.
I'm not sure what else to try.

From the exception you have pasted, I have understood that the orderby parameter is taking two values(i.e start and desc) but it needs only one value. From the intellisence in Graph Explorer we can understand that $orderby=start desc is correct. So here I tried to encode the URL as below and ran it. It worked.
https://graph.microsoft.com/v1.0/me/events?%24orderby%3Dstart desc
There may be some kind of issue in Graph explorer that could be causing this issue or it may be at the server.
This should work for your group events API call as well.

Related

Document's IDs and order by in a query throws an error (Firestore)

As I was trying to get certain documents from Firestore,
I was getting the error:
inequality filter property and first sort order must be the same: __name__ and field
while indexing my Firestore database with this query:
db.collection("collection").whereField(.documentID(), in: array).order(by: "field")
this query works fine without the order by (which is ordering an int).
The issue seems to be that using a document id and an order by statement in a query throws an error.
Are there any work arounds or solutions to this problem?
Thanks!
Firestore can't execute this query because the "in" filter uses document ID (internally known as "__name__"), which is different than your sort order.
The easiest workaround is to simply sort the documents in your app code. Since an "in" query can only return 10 documents maximum, this should pose no real problems at all on modern hardware.

What is the "Alternative Operator" to "Replace Multiple OR statement" in $Filter query of "Microsoft Graph API"

I need to find detail of more than 20 users in one query, so I am trying to use below query, But maximum 15 "or" is allowed in one query. So please let me know operator which I can use instead od using "multiple OR statement"
https://graph.microsoft.com/v1.0/users?$filter=startsWith(userPrincipalName, 'user1') or startsWith(userPrincipalName, 'user2').......
That's a per request threshold and I don't think it can be directly tackled with a drop-in replacement but here's some other ideas for you to consider:
1) If your application stores the user ids you can use the get directory objects by id endpoint which gets up to 1000 users back in one request https://learn.microsoft.com/en-us/graph/api/directoryobject-getbyids?view=graph-rest-1.0&tabs=http
2) Keep your current query but use MS Graph $batch requests to send multiple of these queries in one call to MS Graph. This will require you to construct the JSON batch payload and parse the response. https://learn.microsoft.com/en-us/graph/json-batching

Querying JIRA to Produce Counts of Issues by Different Type

Suppose I have the following JIRA filter.
project = XXX AND resolution = Unresolved AND assignee in (EMPTY) ORDER BY Type asc, priority desc
I use it to see all unassigned issues in a certain project and pull from for triage.
Every now-and-then, I need to know how many are in each Type, i.e., I actually want a count for each.
How could I modify this query to do that or write a new one that accomplishes the same thing?
Remember that JQL isn't SQL - it just operates on tickets and returns lists of them for other parts of JIRA to consume, and doesn't really have a mechanism for counting results.
That said, you can use the JIRA REST API's /search endpoint along with maxResults=0 to construct JQL queries for each Type you care about, and the endpoint will give you a total value for that ticket Type:
https://jira.url/rest/api/latest/search?jql=project%20=%20XXX%20AND%20resolution%20=%20Unresolved%20AND%20assignee%20in%20%28EMPTY%29%20AND%20Type%20=%20Task&maxResults=0
Results in this output for Type=Task:
{
"startAt":0,
"maxResults":0,
"total":123,
"issues":[]
}

Get Microsoft Graph messages by flagStatus using OData $filter

I'm writing Microsoft Graph OData query to get mail messages based on message flagStatus in order to reuse working query in my C# code. How correct query should look like?
Following example is tried in Graph Explorer's sample account where all messages have object flag with field flagStatus = "notFlagged".
https://graph.microsoft.com/v1.0/me/messages?$filter=flag/flagStatus eq 'notFlagged'
It is expected that all messages should be returned. But as a result empty array was given back.
If in query I change eq to ne to be
https://graph.microsoft.com/v1.0/me/messages?$filter=flag/flagStatus ne 'notFlagged'
then all messages are returned. But by me it is expected that here should be empty array in this case.
Considering that maybe flag object isn't ready for filtering, I also tried to $expand it
https://graph.microsoft.com/v1.0/me/messages?$expand=flag&$filter=flag/flagStatus eq 'notFlagged'
but got error message
Property 'flag' on type 'microsoft.graph.message' is not a navigation property or complex property. Only navigation properties can be expanded.
So probably $expand for flag filtering is not needed. But is it possible to filter by message's flag at all?
Also if consider situation that flag object could be null and also flagStatus inside could be null (at least in C# class Microsoft.Graph.FollowupFlag property FlagStatus is nullable), then how query should look like to meet full requrirement below?
Get messages whose
flag is null
or flag/flagStatus is null
or flag/flagStatus is 'notFlagged'
I had the same problem, probably is nullable as suggested. There's only three possible statuses according to the followupFlag documentation, so I worked around it with a not equal and condition for the two other statuses, complete and flagged.
https://graph.microsoft.com/v1.0/me/messages?$filter=flag/flagStatus ne 'flagged' and flag/flagStatus ne 'complete'

MS Graph [V1.0]: $orderBy completely ignores the $skip param

According to the doc, you should be able to use $top,$skip and $orderBy at the same time.
$top & $skip works as expected, but as soon as you add $orderBy it's ignoring the $skip constraint.
you can reproduce the examples below in the graph explorer:
https://graph.microsoft.com/v1.0/me/messages?$select=id,subject&$orderBy=lastModifiedDateTime%20asc&$top=1&$skip=0
https://graph.microsoft.com/v1.0/me/messages?$select=id,subject&$orderBy=lastModifiedDateTime%20asc&$top=1&$skip=1
Your query string is wrong. You miss the $ before skip. The right query string resembles the following:
https://graph.microsoft.com/v1.0/me/messages?$select=id,subject,bodyPreview&$orderBy=lastModifiedDateTime asc&$top=1&$skip=6
Note:
Use some real data to test(no matter real business data or the data from O365 trail account), the API will work well. Not sure why the default mock data doesn't work, maybe PG limit some mock data query. So mock test data only for reference, developer need to create own data source.

Resources