Skip to content

Instantly share code, notes, and snippets.

@xen0bit
Created November 26, 2020 15:13
Show Gist options
  • Save xen0bit/b013605fd59718e0af7b2f3f7f808d5e to your computer and use it in GitHub Desktop.
Save xen0bit/b013605fd59718e0af7b2f3f7f808d5e to your computer and use it in GitHub Desktop.
batch api endpoint get multiple users
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