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":"sample@example.com",
   "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":"sample2@example.com",
   "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
    The user performing the action MUST have "administer users" and "administer permissions" – user28413 Apr 23 '14 at 17:25
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":"user343@sample.com",
   "status":"1",
   "roles":[
      "4"
   ]
}

To assign multiple roles,

{
   "name":"user344",
   "pass":"kes344@r4",
   "mail":"user344@sample.com",
   "status":"1",
   "roles":[
      "3",
      "4"
   ]
}

I hope this helps someone.

|improve this answer|||||
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.

|improve this answer|||||
  • 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 Oct 30 '18 at 14:45

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