I have implemented the following code to get the user for a single upn value. In the below code in the searchCriteria i get the value as "[email protected]" and it returns the user object that matches the upn.
@Override
public AzureResponse getUsersByUPN(Map<String, String> credentials, String searchCriteria) {
log.debug("in getUserByUPN() :start...");
validateToken(credentials);
List<Option> requestOptions = new ArrayList<Option>();
requestOptions.add(new QueryOption("$filter", "startswith(userPrincipalName,'" + searchCriteria + "')"));
List<User> users = new ArrayList<>();
AzureResponse response = new AzureResponse();
try {
UserCollectionRequestBuilder usersClientBuilder = graphClient.users();
UserCollectionRequest usersRequest = usersClientBuilder.buildRequest(requestOptions);
do {
UserCollectionPage userCollectionPage = usersRequest.get();
users.addAll(userCollectionPage.getCurrentPage());
usersClientBuilder = userCollectionPage.getNextPage();
if (usersClientBuilder == null) {
usersRequest = null;
} else {
usersRequest = usersClientBuilder.buildRequest();
}
} while (usersRequest != null);
response.setData(users);
} catch (GraphServiceException e) {
log.error("GraphServiceException occurred in getUserByUPN() : ", e);
setErrorResponse(response, e.getResponseCode(), e.getResponseMessage());
} catch (Exception e) {
log.error("Exception occurred in getUserByUPN() : ", e);
setErrorResponse(response, 400, e.getMessage());
}
log.debug("in getUserByUPN() :end.");
return response;
}
Now i get a List of upn and i want to get all the user objects of those upn's. Is that possible through the above.
For ex : I have a list of upn's like below
List<String> upns = Arrays.asList('[email protected]','[email protected]')
Can i pass this list directly to the QueryOption
List<Option> requestOptions = new ArrayList<Option>();
requestOptions.add(new QueryOption("$filter", "startswith(userPrincipalName,'" + upns + "')"));
Can we query on the list directly or do we need to iterate on the list and pass each upn and get the user object
I have gone through the below link, but could not figure out
https://learn.microsoft.com/en-us/graph/filter-query-parameter?tabs=java
Any help/suggestions please