Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I add attributes to users in crowd using the REST API

Lars Vonk August 3, 2011

Hi,

I am using the Crowd REST Api and it is not clear to me how the requestbody would look like if you want to add an attribute to a user. According to the docs on http://confluence.atlassian.com/display/CROWDDEV/Crowd+REST+Resources#CrowdRESTResources-UserResource you can post this

<?xml version="1.0" encoding="UTF-8"?>
<user name="username" expand="attributes">
<first-name>First</first-name>
<last-name>Last</last-name>
<display-name>First Last</display-name>
<email>email@email.com</email>
<active>true</active>
<attributes>
<link rel="self" href="link_to_user_attributes"/>
</attributes>
<password>
<link rel="edit" href="link_to_user_password"> <!-- /user/password?username=<username> -->
<value>password</value> <!-- only used when creating a user, otherwise not filled in -->
</password>
</user>

in order to create an user.

Let's say I want to add an attribute call "foo" with value "bar", how would the xml body look like then?

Thanks in advance,

Lars

5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
dsounthi June 11, 2013
{"attributes": [ { "name":"priority", "values": [ "1" ] } ] } This one works..BTW @Atlassian why there is no documentation for this? :(
0 votes
Chris Garber May 3, 2013

Has anyone been able to set the attributes using JSON or REST?

0 votes
Van Le September 18, 2012

I tried

[
{"name":"attr-name", "value":"attr-value"},
{"name":"attr-name", "value":"attr-value"}
]
But got no luck.
Anyone succesfully add attribute with JSON body?
Van Le September 18, 2012

The json body must be

attribute_list = {'attributes':[{"name":"attr-name", "values":["attr-value"]}]}

0 votes
xavierx November 17, 2011

Has anyone tried this with a json body?

I tried multiple ways without success:

[attributes:[attribute:['name':'aKyeThatExists',values:[value:'value']]]]

[attribute:['name':'aKyeThatExists',values:[value:'value']]]

['name':'aKyeThatExists',values:[value:'value']]

they all return me 500 internal server error

Darren Schnare December 20, 2011

Try the following JSON:

[
  {"name":"attr-name", "value":"attr-value"},
  {"name":"attr-name", "value":"attr-value"}
]
I'm not currently using JSON as the body format but, I did see an example here: https://answers.atlassian.com/questions/15698/howto-create-crowd-user-using-rest
(Look for Gaurav Kohli's comment)

0 votes
Lars Vonk August 8, 2011

I found it. Apperantly this can not be done in one call. You first have to do a create user using the POST to the /user URL and then you can add attributes to it doing a POST to the /user/attribute?username=USERNAME using a request body like:

<?xml version="1.0" encoding="UTF-8"?>

<attributes>

<attribute name="attribute_test"><values><value>text</value></values></attribute>

</attributes>

This isnt documented on the wiki though.

Adam Laskowski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2011

The example user XML includes all the relevant fields for creating or altering users, so I can see how the comment for password that says, "only used when creating a user..." could be misleading. The POST for managing attributes requires that you specify a username in the URL, and if the username does not exist, the POST will fail before the XML is passed.

You are correct that you need to do a POST to /user to create a new user if one does not exist. We can clarify this more in the description of the method.

Adam Laskowski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2011

The example user XML includes all the relevant fields for creating or altering users, so I can see how the comment for password that says, "only used when creating a user..." could be misleading. The POST for managing attributes requires that you specify a username in the URL, and if the username does not exist, the POST will fail before the XML is passed.

You are correct that you need to do a POST to /user to create a new user if one does not exist. I've altered the description to clarify that it can only be used for existing users.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events