How do I get machine name by entity type and its ID? How do I get machine name by entity type and its ID? 

The code I am using is the following.

$block = \Drupal\block_content\Entity\BlockContent::load(2);
$render = \Drupal::entityTypeManager()-&gt;
getViewBuilder('block_content')-&gt;view($block);
To get the type and id of a given entity, you can do:

$type = $entity-&gt;bundle();
$id = $entity-&gt;id();


Some entities, like Node, provide wrapper methods to return the bundle:

$type = $node-&gt;getType();

But Block doesn't. So if it is Block that you are after:

$block = \Drupal\block_content\Entity\BlockContent::load(2);
$type = $block-&gt;bundle();
$id = $block-&gt;id();