2
votes

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": "[email protected]",
    "mobilePhone": "+1 3528700812",
    "officeLocation": null,
    "preferredLanguage": "en-US",
    "surname": "Administrator",
    "userPrincipalName": "[email protected]"
}

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
Could you explain why you'd want a filtered list with just one user rather than simply grabbing the user object itself? Generally you use the list to find the ID, not to filter by that ID.Marc LaFleur
@MarcLaFleur-MSFT I agree, except that I'd made my own URL generator, and it wasn't flexible enough to handle more than one path element. I wanted to see if I can query by ID using $filter. Now that I can, I should probably think about whether I should :-)Andrew Shepherd

1 Answers

3
votes

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'