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
Community moderators have prevented the ability to post new answers.
{"attributes":
[
{
"name":"priority",
"values":
[
"1"
]
}
]
}
This one works..BTW @Atlassian why there is no documentation for this? :(
Has anyone been able to set the attributes using JSON or REST?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried
[
{
"name"
:
"attr-name"
,
"value"
:
"attr-value"
},
{
"name"
:
"attr-name"
,
"value"
:
"attr-value"
}
]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.