0

Current code:

public render(): void {
this.context.msGraphClientFactory
  .getClient()
.then((graphclient:MSGraphClient): void=>{
  graphclient
  .api('/users')
  .filter('Department eq IT')
  .get((error,user:MicrosoftGraph.User,rawResponse?:any)=>{
    console.log(user)
 }

Fetching users detail through Graph API call and filtering users for a particular Department into web part in SPFx.

Using No JavaScript framework to build this web part.

When not using filter, getting all the users details.

How to use filter in the API call?

1
  • Try below filter queries. let me know if it works for you. Apr 6, 2021 at 8:51

1 Answer 1

1

You can try using filter like below:

.filter("Department eq 'IT'")

OR

.filter("department eq 'IT'")

Update

It is working fine for me:

enter image description here

Endpoint used:

https://graph.microsoft.com/v1.0/users?$filter=Department eq 'Finance'&$select=id,displayName,department

Try giving below permissions:

  • User.ReadBasic.All
  • User.Read.All

enter image description here

5
  • I had tried both the way but not working Apr 6, 2021 at 9:52
  • error: {code: "Authorization_RequestDenied", message: "Insufficient privileges to complete the operation.",…} Apr 6, 2021 at 9:55
  • Check updated answer. try with User.ReadBasic.All and User.Read.All permissions. Apr 6, 2021 at 10:01
  • I am getting the same user data when calling API through graph explorer but when calling the API through code ,getting a error in the console error: {code: "Authorization_RequestDenied", message: "Insufficient privileges to complete the operation.",…} Apr 6, 2021 at 10:25
  • 1
    Is this issue resolved or you still facing any problem with this? Aug 19, 2022 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.