How to create user using jasper rest api?

I am trying to create user by following JasperServer rest api I am using JasperServer version 5.6.0  ,when I am passing put request with json data I am getting 400 Bad Request error

 

 Authenticator.setDefault(new Authenticator() {
  @Override

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("jasperadmin", "jasperadmin".toCharArray());


            }


        });

 String input = "{\"username\":\"AgentUser22\",\"password\":\"jasperadmi\",\"fullname\":\"Agent User\",\"emailAddress\":\"aamitt06@gmail.com\",\"enabled\":true,\"externallyDefined\":false,\"roles\":[{\"name\":\"ROLE_AGENT\"}]}";


        JSONObject jObject  = new JSONObject(input);

         ClientResponse response = service.path("rest_v2").path("users").path("AgentUser22").type("application/json")                .put(ClientResponse.class,jObject);'


          System.out.println(jObject);


           if (response.getStatus() != 201) {


            throw new RuntimeException("Failed : HTTP error code : "  + response.getStatus());


        }

aamitt06's picture
393
Joined: Jun 23 2014 - 5:48am
Last seen: 7 years 4 months ago

After users when I am typing userid that already exists it gives me status 200 that is ok.

aamitt06 - 8 years 11 months ago

1 Answer:

I resolved the issue the mistake i was doing was that in String input = "{\"username\":\"AgentUser22\", ... instead of username it should be fullName and the correct fromat of descriptor should be

 

 String input = "{\"fullName\":\"AgentUser22\",\"password\":\"jasperadmi\",\"emailAddress\":\"aamitt06@gmail.com\",\"tenantid\":\"Ag\",\"enabled\":true,

\"externallyDefined\":false,\"roles\":[{\"name\":\"ROLE_USER\"},{\"name\":\"ROLE_VOUCHER\"}]}";

JSONObject jObject  = new JSONObject(input);

 

Rest would be the same as above.

aamitt06's picture
393
Joined: Jun 23 2014 - 5:48am
Last seen: 7 years 4 months ago
Feedback
randomness