Auth0 Java SDK Management API Update User giving 400 invlid body

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();

I don’t know if you are still looking for an answer to this. But I faced this exact same issue and figured out a solution.

Rather than querying an existing user and updating fields in that object, what you really need to do is to create a new User object and set the fields you need to overlay onto the user in this new object.

Then pass this object in the UsersEntity.update() method along with the user’s Auth0 id.

1 Like