How do I create a role programmatically? How do I create a role programmatically?

What am I doing wrong here?

$role = \Drupal\user\Entity\Role::create(['id' =&gt; 'client', 'name' =&gt; 'Client']);
$role-&gt;save();
The problem is in the data array change name by label:

$role = \Drupal\user\Entity\Role::create(array('id' =&gt; 'client', 'label' =&gt; 'Client'));
$role-&gt;save(); 


Or you can use:

//your data array
$data = array('id' =&gt; 'client', 'label' =&gt; 'Client');
//creating your role
$role = \Drupal\user\Entity\Role::create($data);
//saving your role
$role-&gt;save();