Jump to content
We've recently updated our Privacy Statement, available here ×

add user attributes by Rest_v2 JSON


erikmarbad

Recommended Posts

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

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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-service

It 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

I had missed it. You were right. Sorry.

I tried it too.
Apparently it needs to be done in two steps.


## Step1.Creating User

URL
  http://<host>:<port>/jasperserver[-pro]/rest_v2/users/userID
  ex)http://localhost:8080/jasperserver/rest_v2/users/test_user

Body

{  "fullName":"Test User",  "externallyDefined":false,  "password":"mySecretPassword"}[/code]


## Step2.Adding Attributes

URL
  http://<host>:<port>/jasperserver[-pro]/rest_v2/<entity>attributes<parameters>
  ex)http://localhost:8080/jasperserver/rest_v2/users/test_user/attributes

Body

{    "attribute": [        {            "name": "kokoko",            "value": "yoyoyo"        }    ]}[/code]

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...