Microsoft Graph Api: Filter by GUID value

非 Y 不嫁゛ 提交于 2020-01-05 08:16:32

问题


I am trying to use Microsoft Graph Api to get the details of a specific user.

I have a problem that can be demonstrated using the Graph Explorer: https://developer.microsoft.com/en-us/graph/graph-explorer

If I run this query:

https://graph.microsoft.com/v1.0/users

I get a list of users, including their ID.

I know I can get the details of just one user by appending the id to the url. For example, this query:

https://graph.microsoft.com/v1.0/users/f71f1f74-bf1f-4e6b-b266-c777ea76e2c7

Results in the details of one specific user.

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
    "id": "f71f1f74-bf1f-4e6b-b266-c777ea76e2c7",
    "businessPhones": [],
    "displayName": "CIE Administrator",
    "givenName": "CIE",
    "jobTitle": null,
    "mail": "admin@CIE493742.onmicrosoft.com",
    "mobilePhone": "+1 3528700812",
    "officeLocation": null,
    "preferredLanguage": "en-US",
    "surname": "Administrator",
    "userPrincipalName": "admin@CIE493742.onmicrosoft.com"
}

However, in my case, it would be easier to apply a $filter query on the id field.

Here is what I have tried, and the errors I get:

Attempt One

.../users?$filter=id eq f71f1f74-bf1f-4e6b-b266-c777ea76e2c7

Returns the following message:

A binary operator with incompatible types was detected. Found operand types 'Edm.String' and 'Edm.Guid' for operator kind 'Equal'.

Attempt Two

..../users/$filter=id eq guid'f71f1f74-bf1f-4e6b-b266-c777ea76e2c7'

Returns the following message:

Unrecognized 'Edm.String' literal 'guid'f71f1f74-bf1f-4e6b-b266-c777ea76e2c7'' at '6' in 'id eq guid'f71f1f74-bf1f-4e6b-b266-c777ea76e2c7''.


回答1:


Finally figured it out.

Simply wrap the guid in single quotes, with no other annotations.

https://graph.microsoft.com/v1.0/users?$filter=id eq 'f71f1f74-bf1f-4e6b-b266-c777ea76e2c7'


来源:https://stackoverflow.com/questions/44769844/microsoft-graph-api-filter-by-guid-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!