9

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.

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.

  • 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

protected by Community Mar 17 '15 at 6:09

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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