I'm almost new user of Drupal, but I encountered the same problem because I write myself my modules.
My need is to create a node and to insert it as submenu of a main menu Item. I solved my problem in this way:
I wrote this function
function mymodule_get_plid($menu_name , $name) {
$menu = menu_tree_all_data($menu_name);
foreach ($menu as $item => $menuitem) {
if ($name == $menuitem['link']['link_title']) {
return $menuitem['link']['mlid'];
break;
}
}
return false;
}
where $menuname is a string like 'main-menu', $name is the menu item for which I'm searching for it's Id. Function return Id if it find $name, false otherwise.
Now to complete node creation i wrote this.
$node = new stdClass();
$node->title = "YOUR TITLE";
$node->type = "page"; // Creating a node of Basic page type
node_object_prepare($node); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
$node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
$node->uid = $account->uid;
$node->status = 1; //(1 or 0): published or not
$node->promote = 0; //(1 or 0): promoted to front page
$node->comment = 0; // 0 = comments disabled, 1 = read only, 2 = read/write
$node->menu['enabled'] = TRUE;
$node->menu['menu_name'] = 'main-menu';
$node->menu['plid'] = mymodule_get_plid('main-menu' , 'Inquiries');
$node->menu['link_title'] = 'MY SUBMENU NAME';
$node->menu['description'] = ''; // Needed even if empty to avoid notices. /*
$node = node_submit($node); // Prepare node for saving
node_save($node);
Now all behaves well, "MY SUBMENU NAME" is created as a new node and appended as sub menuitem of the 'Inquiries' menu Item of the main menu.