Am using Java SDK to update user name.
UsersApi usersApi = new UsersApi(apiClient);
User body = new User();
user.setName("XXXX");
usersApi.patchUserId(userId, user) ;
API works successfully without error or exception.
When I fetch UserMe, it gives the old user name
UsersApi usersApi = new UsersApi(apiClient);
UserMe userMe = usersApi.getMe(Arrays.asList("presence"));
System.out.println("user name " + userMe.getName()); -> Prints the old user name.
Am I using the right API to update username?
Please let me know if am doing anything wrong?
Thanks!
It looks like you may still be using the prerelease SDK (version 0.x.x)? Information about the stable release (1.0.0+) can be found here: https://developer.mypurecloud.com/forum/t/java-sdk-stable-release-1-0-0/1204
A few thoughts about your code:
- You're creating a
User
object in a variable named body
, but then set the name and make the update using the variable user
. If that's not just a typo in your post, that's probably part of your issue.
- You're not setting the version on the updated user. You must send the version of the entity that you believe to be current to ensure that you don't overwrite changes you didn't know about.
- Your example code is updating a user by ID, but then calling getMe to retrieve the logged in user. While there's nothing technically wrong with this, there's the possibility that the user that you're updating and the user you're logged in with aren't the same user. This is only a problem if there's human error involved, but getting the user by the same ID you used to make the update will protect against making a mistake there.
This code works correctly using platform-client-v2:9.1.1:
// Get user
User user = _usersApi.getUser(id, null);
System.out.println("User name before: " + user.getName());
// Update user
UpdateUser body = new UpdateUser();
body.setName(name);
body.setVersion(user.getVersion());
_usersApi.patchUser(id, body);
// Get user again
User user2 = _usersApi.getUser(id, null);
System.out.println("User name after: " + user2.getName());