erikmarbad Posted July 6, 2022 Share Posted July 6, 2022 I am trying to add attributes to a user via rest_v2, I have managed to add the roles of this user, but his attributes have not, any help on why the following does not work for the attributes?JSONArray roles = new JSONArray(); JSONArray atributos = new JSONArray(); roles.put(new JSONObject().put("name", "ROLE_USER").put("name", "ROLE_PRUEBA")); //Solo para crear el usuario atributos.put(new JSONObject().put("name", "kokoko").put("value","yoyoyo")); JSONObject jsonBodyInfo = new JSONObject(); try { //jsonBodyInfo.getJSONObject(user).remove(user); Para eliminar un usuario (Se ignora lo demas) jsonBodyInfo.put("fullName", user); jsonBodyInfo.put("enabled", enabled); jsonBodyInfo.put("password", pwd); jsonBodyInfo.put("roles", roles); jsonBodyInfo.put("attribute", atributos); } catch (JSONException e) { } Link to comment Share on other sites More sharing options...
yama818 Posted July 6, 2022 Share Posted July 6, 2022 Comparing your code with the following manual, the way you wrote it looked different.https://community.jaspersoft.com/documentation/tibco-jasperreports-server-rest-api-reference/v790/attributes-serviceIt may be necessary to use a set of 'name'+'value' as follows. { "attribute":[ { "name": "Attr1", "value":"Value1" }, ... { "name": "AttrN", "value":"ValueN" } ]}[/code] Link to comment Share on other sites More sharing options...
erikmarbad Posted July 7, 2022 Author Share Posted July 7, 2022 Hello, I already do the name + value part with the following instruction:atributos.put(new JSONObject().put("name", "kokoko").put("value","yoyoyo")); Link to comment Share on other sites More sharing options...
yama818 Posted July 8, 2022 Share Posted July 8, 2022 I had missed it. You were right. Sorry.I tried it too.Apparently it needs to be done in two steps.## Step1.Creating UserURL http://<host>:<port>/jasperserver[-pro]/rest_v2/users/userID ex)http://localhost:8080/jasperserver/rest_v2/users/test_userBody{ "fullName":"Test User", "externallyDefined":false, "password":"mySecretPassword"}[/code]## Step2.Adding AttributesURL http://<host>:<port>/jasperserver[-pro]/rest_v2/<entity>attributes<parameters> ex)http://localhost:8080/jasperserver/rest_v2/users/test_user/attributesBody{ "attribute": [ { "name": "kokoko", "value": "yoyoyo" } ]}[/code] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now