Why "Parsing Select and Expand failed" error - microsoft-graph-api

I'm writing an app that will call various Microsoft Graph API. What could explain the above error with this API call?
https://graph.microsoft.com/beta/users?$select=id,displayName$filter=accountEnabled eq true

Can't post a comment, so I try it with an answer. :)
You missed a "&" in your URL before $filter.
You have to concat the diffrent options with "&".
Try it with:
https://graph.microsoft.com/beta/users?$select=id,displayName&$filter=accountEnabled eq true
Btw. this call is available in "v1.0". Maybe you can change this as well.
https://graph.microsoft.com/v1.0/users?$select=id,displayName&$filter=accountEnabled eq true

Related

Replacing slack app mentions with usernames in the slack message log in Dataweave

I'm parsing the slack message log from conversations.history and any app mentions come in as <#XX12345>. I'm trying to parse the XX12345 part in a conversation and replace it with username and get rid of the < and >. For eg:
Hello <#UA12345> how are you?
I'm good <#UA67890>. How about you?
should become
Hello #lookup(UA12345) how are you?
I'm good #lookup(UA67890). How about you?
How do I achieve this using replace and regex in DataWeave? The lookup function is used to get the user name from Slack API. This function also needs to be triggered inside Dataweave (not sure if this is even possible). End result would be something like this:
Hello #Adam how are you?
I'm good #David. How about you?
Assuming the username in <#UA67890> is alphanumeric, you can use the following expression to get the required result
yourText replace /\<\#([a-zA-Z0-9]*)\>/ with "#$(getUsername($[1]))"
This matches the regex \<\#([a-zA-Z0-9]*)\> which captures alphanumeric value in between a <# and > in a group and then replace it with #$(getUsername($[1])), i.e. #getUsername(everything that was captured as in the above group)
You can create the function getUsername to actually call the lookup function and call the required flow. So your DataWeave will look something like this.
%dw 2.0
output text/plain
fun getUsername(userid) = lookup('get-user-name-flowname', userid) // Any other transformation that you may need for passing the required payload before calling loopup
var conversation =
"Hello <#UA12345> how are you?
I'm good <#UA67890>. How about you?"
---
conversation replace /\<\#([a-zA-Z0-9]*)\>/ with "#$(getUsername($[1]))"
Update: As mentioned in comment, you also need a flow get-user-name-flowname that will either use slack's REST API or <slack:get-usersprofileget> which will accept this ID and will return the username of the user

Filtering on "null" or "no values"

I am trying to make a filter in Graph API, querying for employees without phone, but with no luck.
This is a part of the query I am working on.
https://graph.microsoft.com/beta/users?$filter=userType eq 'Member'&$select = businessPhones
This results in something like this:
{ "businessPhones": ["+473456789"]},
{ "businessPhones": ["+479876543"]},
{ "businessPhones": ["+471234567"]}
What I am trying to do is ask for users without a businessphone
{ "businessPhones": []}
Something like this
https://graph.microsoft.com/beta/users?$filter=userType eq 'Member' and businessPhones eq ''
However, I have no clue on how to do this. Anyone?
EDIT, thanks Tiny Wang for pointing out "no filtering support":
businessPhones does not support filtering. However, assignedLicenses does. If I want to query for users without any assignedLicenses
{ "assignedLicenses" : [] }
How can I accomplish that?
Pls note, according to the api properity doc, businessPhones isn't a properity supporting $filter, see https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-beta#properties
==========================UPDATE============================
Per my testing, I think it's also an unachievable task. It seems there're some 'defect' exists in ms graph OData filter. In this case, we need to use not assignedLicenses/any() according to OData protocol.
But according to my testing result, the query doesn't support using assignedLicenses/any()->Error: Complex query on property assignedLicenses is not supported , not assignedLicenses/any()->Error: Unsupported Query", but only support like assignedLicenses/any(x:x/skuId eq 3b555118-xxxx-e2096870).
What's more, when executing below query, it returns error Complex query on property assignedLicenses is not supported.
https://graph.microsoft.com/beta/users?$filter=userType eq 'Member' and assignedLicenses/any(x:x/skuId eq 3b555118-xxxx-2096870)&$select=assignedLicenses
But when executing this, it worked, so weird.
https://graph.microsoft.com/beta/users?$filter=assignedLicenses/any(x:x/skuId eq 3b555118-xxxxxx-df1e2096870)&$select=assignedLicenses
I also tried to use $count property to do the filter, but also failed:
I had the same task. After some research, I figured out how to filter out null string properties such as jobTitle, department, etc. Check this link.
Based on the answer, I tried the following query, and It works for me.
https://graph.microsoft.com/v1.0/users?$filter=NOT (businessPhones/any(p:p ge ' '))&$count=true
Be sure that you specified whitespace between quotes ' '.

[MS Graph]: Handling special characters in string search in a MS graph query

I am searching for an object with a display name. MS graph throws an exception if it contains & or # withing the search string. Is there a way around this??
https://graph.microsoft.com/XXXXXXXXXXXXXXXXXXXXXXXXXXXX?$filter=displayName eq 'application # manager'
You need to URL encoding the '#' in the request.
For example below request will help you in querying 'application # manager',
https://graph.microsoft.com/v1.0/users?$filter=displayName eq 'application%20%23%20manager'
For more details look in to Output in my environment below:-

Using OR in filters for Office 365 Service Communications API or filtering by multiple IDs

How can I filter by multiple IDs using the Office 365 Service Communications API?
I'm getting the current status using https://manage.office.com/api/v1.0/{tenent}/ServiceComms/CurrentStatus which gives me incident IDs. I'm trying to use those IDs to get the messages affiliated but the message endpoint /ServiceComms/Messages is not working well with the filters.
The documentation shows:
I've tried:
/ServiceComms/Messages?ID=CR555555,/ServiceComms/Messages?ID='CR555555', /ServiceComms/Messages?Id=CR555555,/ServiceComms/Messages?Id='CR555555' - Returns everything (doesn't filter)
/ServiceComms/Messages?$filter=ID eq 'CR555555' - Returns Error
/ServiceComms/Messages?$filter=Id eq 'CR555555' - Returns 1 result
/ServiceComms/Messages?$filter=Id eq 'CR555555' or Id eq 'CR555556' - Returns error
I was able to get an AND result using
$filter=MessageType eq Microsoft.Office365ServiceComms.ExposedContracts.MessageType'Incident' and EndTime ge 2019-07-25T00:00:00Z but OR always errors with the message "Filter {filter} is invalid. Expected '<Item> <operator> <Value>' pattern."
You need to use Microsoft.Office365ServiceComms.ExposedContracts.MessageType'Incident' as your MessageType.
A request to /Messages should return you a odata context at the top of the response. For example:
{
"#odata.context": "https://office365servicecomms-prod.cloudapp.net/api/v1.0/{{TenantID}}/$metadata#Messages",
...
}
If you query that, you receive the metadata along with the possible filters. I cannot give you an example as of today (2020-02-16) a query returns a 500 Internal Server Error. Microsoft is working on a fix. Maybe it works again by the time you read my reply.
Complete example:
https://manage.office.com/api/v1.0/{{TenantID}}/ServiceComms/Messages?$filter=MessageType eq Microsoft.Office365ServiceComms.ExposedContracts.MessageType'Incident' and LastUpdatedTime ge 2020-02-13T00:00:00.000Z
And yes, the ID filter must be written 'Id'. Microsofts documentation has a lot of wrong information in it.

microsoft graph API using filter on get sharepoint items

i am trying to filter my Sharepoint Items results query with the Microsoft Graph API as explained here so i am trying this
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items
so i tried adding
?&filter=od eq 1, or copying from expand ?filter=fields(select%3Did) = 1, none works. please help
FOUND IT!
&filter=fields/id eq 1
&filter=fields/ContentType eq 'Apartment Page' -> NO DOUBLE QUOTES
&filter=startswith(fields/id,1)
#mhbuur
add request header
Prefer: HonorNonIndexedQueriesWarningMayFailRandomly
You don't need to filter by id just do:
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/{id}

Resources