Hi
I am trying to update the user_metadata via the auth0-java API. I have requested the API token and manged to request the user account. I then got the User Metadata as a HashMap and then updated it with new values. I then added the hashmap to the user object. Made a request to update the user and got the following exception:
com.auth0.exception.APIException: Request failed with status code 400: Payload validation error: ‘Additional properties not allowed: logins_count,last_login,last_ip,identities,updated_at,created_at,user_id (consider storing them in app_metadata or user_metadata. See “Users Metadata” in Past Migrations for more details)’.
I am using version 1.31.0 of the sdk. The following is my code snippet.
AuthAPI authAPI = new AuthAPI(auth0ConfigurationProperties.getDomain(), auth0ConfigurationProperties.getClientID(), auth0ConfigurationProperties.getClientSecret());
AuthRequest authRequest = authAPI.requestToken("https://" + auth0ConfigurationProperties.getDomain() + "/api/v2/");
TokenHolder holder = authRequest.execute();
ManagementAPI mgmt = new ManagementAPI(auth0ConfigurationProperties.getDomain(), holder.getAccessToken());
User user = mgmt.users().get(accountInformation.getUserid(), new UserFilter()).execute();
Map<String, Object> userMetaData = user.getUserMetadata();
userMetaData.put("accountType", accountInformation.getAccountType());
userMetaData.put("firstName", accountInformation.getFirstName());
userMetaData.put("displayName", accountInformation.getDisplayName());
user.setUserMetadata(userMetaData);
Request<User> request = mgmt.users().update(accountInformation.getUserid(), user);
User response = request.execute();