Set Password for user from Java SDK

Can I set a user’s password at anytime as “admin/service” account? I am using the Java SDK and referencing [Users | Okta Developer](Set Password)

Below is the Groovy code:

Client client = Clients.builder()
    .setClientCredentials(new TokenClientCredentials("${apiToken}"))

UserList users = client.listUsers(user.getEmail(), null, null, null, null)
User user1 = users?.first()
String userId = user1?.getId()

Resource userPasswordRequest = client.instantiate(ExtensibleResource)
userPasswordRequest.put("credentials", client.instantiate(ExtensibleResource)
    .put("password", client.instantiate(ExtensibleResource)
    .put("value", password.toCharArray())))
Resource result = client.getDataStore().http()
    .post("/api/v1/users/"+ userId, User.class)"Result: ${result}")

I did not get any errors but the password is unchanged.

Is there a reason you’re not using the UserCredentials setPassword method to do this? This one should work for a super admin to be able to set the password for any user.

@Andrea thanks for the suggestion, the code below worked when creating a User. I will try using UserCredentials.setPassword method.

        User user = UserBuilder.instance()
        .setBcryptPasswordHash(passwordHash, salt, rounds)