“Creating Users in Drupal with REST”

This is a very basic example to create a user with a specific role in Drupal 8 with “Rest”. First we will use a Chrome extension called “DHC by Restlet”. Through this extension, I create a JSON with some information to create our user, this tool is simple to use but I’ll give you some simple tips:

a- First thing to do is install our module Drupal 8 “Rest” and enable it, the path is: / admin / modules.

b-Then we’ll configuration, look for the option to “Rest” and then we enter, we enable resource in Rest user the option to then edit it, the path is: / admin / config / services / rest.

c- After entering the option to edit user we will set up various options and adjust to our example options as we create our user for example we mark “post”, “delete”, “get”, “patch” options and the option “ Supported formats “will mark the option” JSON “for each request.

d- Then in the option “Authentication providers” we will mark the option “Basic_Auth” and then save those changes.

For this example where we will use “DHC by Restlet” to create our user, we will put these data:

Get the token at: http://example.com/rest/session/token

POST Request

Request: http://example/entity/user

Headers

Header Name

Header Value

X-CSRF-Token

(Token from “http://example.com/rest/session/token” )

Authorization

Basic (hashed username/password)

Content-Type

application/json

Accept

application/json

Body

{

“name”:”Example”,

“pass”:”123456",

“mail”:”example@outerspacecoders.com”,

“status”:”1",

“roles”:[

“player”

]

}

Response

200 OK