0

Our company has many systems that require for users to have user names and passwords. We have been able to use SAML to cut down on the number of accounts we must manually create. With that said, we do currently manually create Drupal users.

Would it be possible to have an "external script" provide Drupal with the variables it needs to create a new user.

Example:

External system collects user information in one spot.
1) User is created in Drupal according to data passed
2) Users are simultaneously created in other systems.

If it were not Drupal, I would google "API" for the system but with Drupal, I think API can mean a lot of different things and I was not able to easily find anything that might point me in the right direction.

3
  • 1
    "drupal REST API" will get you more focused hits if you're talking about doing this over HTTP. If not, then just "drupal create user programtically" – Clive Aug 21 '18 at 19:04
  • Ok. Thank you. I will try the googling REST API. If I find something good I will share and close out the item. – Scott Aug 21 '18 at 19:07
  • Per Clive, I should have been looking for this using the REST API. I found a great article. Thanks Clive! drupedia.org/blog/development/… – Scott Aug 21 '18 at 19:11
1

And also it's very simple to create users in D8 by program:

$newuser = \Drupal\user\Entity\User::create([
          'name' => $name,
          'pass' => $pass,
          'mail' => $mail, 
          'status' => 1,  // or 0 if inactive
          'init' => $initmail,
          'created' => time(),
          'login' => 0,
          'access' => 0,
        ]);
      $newuser->addRole("myrole");
      $rc = $newuser->save();
      if ($rc == SAVED_NEW) {
    ...whatever...
    }

For bootstrapping external scripts, you can look i.e. here: Bootstrap from external script

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