I am trying to get users from Active Directory using Graph API. For this i am using a list of user id's.
String selectQuery = "id,mail,givenName,surname,displayName,businessPhones,department,assignedLicense";
List<Option> requestOptions = new LinkedList<>();
requestOptions.add(new QueryOption("$select", selectQuery));
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(new SimpleAuthProvider(accessToken)).buildClient();
List<User> users = new ArrayList<>();
for (String userID : userList) {
IUserRequest request = graphClient
.users()
.byId(userID)
.buildRequest(requestOptions);
users.add(request.get());
}
return users;
Using the code above i receive the input below.
[com.microsoft.graph.models.extensions.User@5042e9c3, com.microsoft.graph.models.extensions.User@1c9fc2e2]
I would like to receive user resource fields(such as mail, givenName, surname, displayName, businessPhones etc.) for users which i am searching. I used a sample query in Graph Explorer. But i fail to get multiple users with java sdk. How can i achieve this?
Your code is correct and you have got the users.
You need to poll users
and get their corresponding attributes, like this:
for (User user : users) {
System.out.println("id:" + user.id + " mail:" + user.mail + " displayName:" + user.displayName);
}