10

I could able to create a new user by the following JSON format.(Using POSTER add-on to post this data to REST service.)

{
   "name":"user34",
   "pass":"3323",
   "mail":"[email protected]",
   "status":"1"
}

My question is how to create a user with specific role. I tried with the following JSON format.

{
   "name":"user35",
   "pass":"pwds3",
   "mail":"[email protected]",
   "status":"1",
   "roles":{
      "2":"authenticated user",
      "4":"moderator"
   }
}

but the response gives the following error

["An illegal choice has been detected. Please contact the site administrator."]

1
  • 1
    The user performing the action MUST have "administer users" and "administer permissions"
    – user28413
    Commented Apr 23, 2014 at 17:25

2 Answers 2

16

After many trials, I was able to resolve my issue

Here is the JSON format to create user with role.

{
   "name":"user343",
   "pass":"kes35@r4",
   "mail":"[email protected]",
   "status":"1",
   "roles":[
      "4"
   ]
}

To assign multiple roles,

{
   "name":"user344",
   "pass":"kes344@r4",
   "mail":"[email protected]",
   "status":"1",
   "roles":[
      "3",
      "4"
   ]
}

I hope this helps someone.

3
  • Which is the url to create new user in poster
    – KTM
    Commented Feb 17, 2016 at 15:49
  • my_url/rest_endpoint/user and posted via rest client (ARC) of chrome
    – KTM
    Commented Feb 17, 2016 at 16:22
  • Can you list which all processes can do by through rest client ??
    – KTM
    Commented Feb 17, 2016 at 16:22
0

This helped!

I used the request URL endpoint/user/register and passed headers content-type as application/json and X-CSRF-TOKEN which I got by login to the system.

Thanks.

1
  • When registering a new user how would you get a X-CSRF-TOKEN? you mentioned that you got token by login to the system, but user should be registered first before that can login.
    – IAM
    Commented Oct 30, 2018 at 14:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.