Created
November 26, 2020 15:13
-
-
Save xen0bit/b013605fd59718e0af7b2f3f7f808d5e to your computer and use it in GitHub Desktop.
batch api endpoint get multiple users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const options = { | |
authProvider, | |
}; | |
const client = Client.init(options); | |
//Despite "supporting" id's for requests, I seem to remember them being required last time I tried it? | |
//Get the current user, and get the displayName and givenName of a user by their UPN | |
const batchGetUsers = { | |
"requests": [{ | |
"id": "1", | |
"method": "GET", | |
"url": "/me" | |
}, { | |
"id": "2", | |
"method": "GET", | |
"url": "/users/{userPrincipalName}?$select=displayName,givenName" | |
} | |
] | |
} | |
let res = await client.api('/$batch') | |
.post(batchGetUsers); | |
//Should be roughly equivalent to | |
/*POST /v1.0/$batch HTTP/1.1 | |
Host: graph.microsoft.com | |
Content-Type: application/json | |
{ | |
"requests": [{ | |
"id": "1", | |
"method": "GET", | |
"url": "/me" | |
}, { | |
"id": "2", | |
"method": "GET", | |
"url": "/users/{userPrincipalName}?$select=displayName,givenName" | |
} | |
] | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment