Remote Entity Create with Node Reference I am writing an Android app which is creating Drupal nodes remotely.  I am creating these nodes via a straight php form.  But now I need to create Nodes which are node_references of the main node.  Usually in order to do this you will need the entity ID of the main node before you can create a node reference.

Creating the second node as a reference should be easy as it is just an extra field with a reference value in it.  The problem is, once the App creates the main node, I need the entity ID to be returned to the App so that the value can be used to create the other referenced node.

How do I get the entity ID back as a return value after node creation?

or... am I thinking about this all wrong  :)
If you are using the entity api to create and save your entity its fairly easy:

// Create the node and wrap it in entity metadata wrapper
$node_create = entity_create('node', array('type' =&gt; 'my_content_type'):
$node_wrapper = entity_metadata_wrapper('node', $node_create);

$node_wrapper-&gt;title-&gt;value("My Title"); // Set the title
$node_wrapper-&gt;save(); // Node is now saved
$node_nid = $node_wrapper-&gt;getIdentifier(); // We now have the nid

// Doing the same thing here except adding the reference
$node_create2 = entity_create('node', array('type' =&gt; 'my_other_content_type'):
$node_wrapper2 = entity_metadata_wrapper('node', $node_create2);

$node_wrapper2-&gt;title-&gt;value("My referenced title");
$node_wrapper2-&gt;field_node_reference-&gt;value($node_nid);

$node_wrapper2-&gt;save();