The SDK provides two ways to perform asynchronous operations depending on which API you are using.
Management API
The Management API provides a dedicated AsyncManagementApi client. All operations on this client return a CompletableFuture.
Authentication API
The AuthAPI supports asynchronous execution via the .executeAsync() method on request objects, which returns a CompletableFuture.
// Management API Async
AsyncManagementApi asyncClient = new AsyncManagementApi(clientOptions);
CompletableFuture<GetUserResponseContent> future = asyncClient.users().get("user_id");
future.thenAccept(user -> {
System.out.println(user.getEmail());
});
// Authentication API Async
AuthAPI auth = AuthAPI.newBuilder("{YOUR_DOMAIN}", "{YOUR_CLIENT_ID}", "{YOUR_CLIENT_SECRET}").build();
CompletableFuture<TokenHolder> future = auth.requestToken("https://{YOUR_DOMAIN}/api/v2/").executeAsync();
future.thenAccept(holder -> {
String accessToken = holder.getBody().getAccessToken();
});