Assigning role using REST API

31 views
Skip to first unread message

MobDev

unread,
Oct 12, 2014, 8:37:22 PM10/12/14
to mobile-c...@googlegroups.com
Hey guys, Could you please help me, I am trying to assign role to a user with REST API.

I am creating users with following:

http://$URL:4985/$DB/_user/$USERNAME
{
"name":"$USERNAME",
"password":"$PASSWORD"
}

I tried putting "roles" in the above json. 


Thanks a lot in advance.

Cheers,







Jens Alfke

unread,
Oct 13, 2014, 12:02:57 AM10/13/14
to mobile-c...@googlegroups.com

> On Oct 12, 2014, at 5:37 PM, MobDev <ehdev...@gmail.com> wrote:
>
> I tried putting "roles" in the above json.

That should work. Show us the exact JSON you tried, and the exact error you got.

—Jens

MobDev

unread,
Oct 13, 2014, 12:21:23 AM10/13/14
to mobile-c...@googlegroups.com
Hi Jens, 

{
"name":"$USERNAME",
"password":"$PASSWORD",
"roles":["$ROLENAME"]
}

I have created role before creating user.

Thanks a lot.

Cheers,

Jens Alfke

unread,
Oct 13, 2014, 12:48:53 AM10/13/14
to mobile-c...@googlegroups.com
"$" isn't a valid character in a role name. (You are showing the exact JSON as I asked, right?)

—Jens

MobDev

unread,
Oct 13, 2014, 12:59:15 AM10/13/14
to mobile-c...@googlegroups.com
Nope. Sorry, I was using $  sign as variable. I have changed that in the following json with role name.

{
"name":"$USERNAME",
"password":"$PASSWORD",
"roles":["allusers"]
}

ajres

unread,
Oct 13, 2014, 4:29:11 AM10/13/14
to mobile-c...@googlegroups.com
@MobDev

When setting explicit roles via the REST API, you should use the 'admin_roles' property.

For your example try the following:

http://$URL:4985/$DB/_user/$USERNAME
{
"name":"$USERNAME",
"password":"$PASSWORD",
"admin_roles":["allusers"]
}

A users 'roles' property is dynamically generated from a user's explicit roles set using 'admin_roles' on the REST API and the roles dynamically assigned via the sync function.

Andy

MobDev

unread,
Oct 13, 2014, 12:53:14 PM10/13/14
to mobile-c...@googlegroups.com
That worked. Thanks a lot Andy.

Cheers,
Reply all
Reply to author
Forward
0 new messages