Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set only certain properties when updating a user. #58

Closed
brettcooper opened this issue Jun 8, 2017 · 4 comments
Closed

Comments

@brettcooper
Copy link

When calling the management API to update a user, I am always receiving the following exception:

com.auth0.exception.APIException: Request failed with status code 400: Payload validation error: 'Additional properties not allowed: logins_count,last_login,identities,updated_at,created_at,nickname,name,picture,user_id (consider storing them in app_metadata or user_metadata. See "Users Metadata" in https://auth0.com/docs/api/v2/changes for more details)'.

According to the Auth0 API documentation, it looks like we should only be sending properties for the user that have changed (e.g. - email, email_verified, user_metadata, etc.) But, with the current API's implementation, this is not possible and I have had to write my own REST call to make this work (I am just trying to update a user so that user is blocked).

Something similar to this should work:

public Request<User> update(String userId, String json) {
    Asserts.assertNotNull(userId, "user id");
    Asserts.assertNotNull(json, "json");
    String url = this.baseUrl.newBuilder().addPathSegments("api/v2/users").addPathSegment(userId).build().toString();
    CustomRequest<User> request = new CustomRequest(this.client, url, "PATCH", new TypeReference<String>() {
    });
    request.addHeader("Authorization", "Bearer " + this.apiToken);
    request.setBody(json);
    return request;
}
@lbalmaceda
Copy link
Contributor

@brettcooper The server won't let you call that endpoint sending any of those attributes. When you call PATCH you just send the attributes that you want to change, not the whole user object.. In the practice you'd do that if the Http method is PUT. So if you're trying to change the blocked attribute, just send that.

@brettcooper
Copy link
Author

@lbalmaceda Is it currently possible to do this with the Auth0 Java client? If so, can you point me in the right direction or can you provide an example?

@lbalmaceda
Copy link
Contributor

User should have a public constructor with no args but it seems it's missing. Anyway, if you see the code the same can be achieved by passing a null connection.

        ManagementAPI managementAPI = new ManagementAPI("the_domain","the_api_token");
        User user = new User(null);
        user.setBlocked(true);
        managementAPI.users().update("your_user_id", user).execute();

@brettcooper
Copy link
Author

Perfect. Thanks @lbalmaceda !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants