Bootstrap from external script I am trying to create Drupal entity instances from an external script that is not part of Drupal or a Drupal module.

For Drupal 7 there was drupal_bootstrap to load the required Drupal dependencies. However, after a long search all I found for Drupal 8 was a note that drupal_bootstrap is deprecated for Drupal 8.

And indeed, I get a


  Call to undefined function drupal_bootstrap()


when I try to call it after including as in

define('DRUPAL_ROOT', __DIR__ .'/../drupal');
require_once DRUPAL_ROOT . '/core/vendor/autoload.php';
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);


So how can I use the Drupal 8 API from an outside script?!
For current version of drupal 8.x:

define('DRUPAL_DIR', '/usr/share/nginx/html');
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
require_once DRUPAL_DIR . '/core/includes/database.inc';
require_once DRUPAL_DIR . '/core/includes/schema.inc';
// Specify relative path to the drupal root.
$autoloader = require_once DRUPAL_DIR . '/autoload.php';

$request = Request::createFromGlobals();

// Bootstrap drupal to different levels
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel-&gt;boot();
$kernel-&gt;prepareLegacyRequest($request);

$em = $kernel-&gt;getContainer()-&gt;get('entity.manager');

$entity = $em-&gt;getStorage('node')-&gt;create(
        array(
          'type' =&gt; "article",
          'title'=&gt; "test entity",
          'body' =&gt; "body body body",
        ));

$entity-&gt;save();