Programmatically create a node with alias and menu item using Entity API I've seen the excellent documentation on Drupal.org about how to create a node in code, but that documentation doesn't address how to create the node's alias.  I've seen code snippets that use $node-&gt;path; and $node-&gt;menu with node_save($node); which works, but with $entity-&gt;path-&gt;set(); or with $entity-&gt;menu-&gt;set(); I'm receiving the following error message:


  Unknown data property path.
  Unknown data property menu.


Why does this not work with entity api and how can I modify my code (below) to make it work?

&lt;?php
/**
 * Testing programatic content creation.
 */
function mymodule_update_7000() {
  $about = _create_node_and_menu_item('About', 'about', 'main-menu', 'About the site');
  dpm($about);
}

/**
 * Helper function creates a node, with alias, and menu item, and
 * returns the mlid.
 * @param  string  $title      the title of the node
 * @param  string  $alias      the URL alias
 * @param  string  $menu_name  the machine name of the menu, eg 'main-menu'
 * @param  string  $menu_title the title of the menu item, if none is
 *                             provide, the $title will be used.
 * @param  integer $plid       the numeric id of the parent menu item
 *                             (defaults to 0).
 * @param  integer $uid        the numeric user id (defaults to 1)
 * @param  string  $body       the body copy to use on the node, defaults
 *                             to lorem ipsum.
 * @return Entity              the node entity object that was created.
 */
function _create_node_and_menu_item($title, $alias, $menu_name = '', $menu_title = '', $plid = 0, $uid = 1, $body = '') {
  if (!$body) {
    $body = '&lt;p&gt;Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus&lt;/p&gt;';
  }
  $node = entity_create('node', array(
    'type' =&gt; 'page',
    'uid' =&gt; $uid,
    'status' =&gt; 1,
    'comment' =&gt; 1,
    'promote' =&gt; 0,
  ));

  // Get a wrapper for adding meta-data.
  $entity = entity_metadata_wrapper('node', $node);
  // Using the wrapper, we do not have to worry about telling Drupal
  // what language we are using. The Entity API handles that for us.
  $entity-&gt;title-&gt;set($title);
  $entity-&gt;body-&gt;set(array('value' =&gt; $body));

  if ($alias) {
    // FIXME this line is broken :'(
    $entity-&gt;path-&gt;set(array('alias' =&gt; $alias));
  }
  if ($menu_name) {
    if (!$menu_title) {
      $menu_title = $title;
    }
    // FIXME this line is broken :'(
    $entity-&gt;menu-&gt;set(array(
      'link_title' =&gt; $menu_title,
      'menu_name' =&gt; $menu_name,
      'plid' =&gt; 0,
      'enabled' =&gt; 1,
    ));
  }
  // Save the entity and its meta-data.
  $entity-&gt;save();
  return $entity;
}


I realize there are other ways to create a path using path_save(), but this is predicated on knowing the node id first.  A valid answer here would show how to do this purely with Entity API and one call to $entity-&gt;save(). Is it possible?
I would suggest that you use the node_save() and have a $node-&gt;path set to create the desired path alias, rather than using $entity-&gt;save() because if inspect (via dpm()) the output of an entity_load() of a node, you would see nothing there related to the node's path alias.

Of course you could use $entity-&gt;save() > then fetch the node/entity id > and then use [path_save()][1] too.