Update a menu link programmatically For a migration project, we had some links on the main menu stubbed out to an external site. Now I want to update the links with their actual final path. However, I can't do this beforehand, because I don't know what the node ids of the newly-created imported nodes would be. 

I want to update the menu links with node ids in my import script, but I haven't found how to do that programmatically. We would like to avoid updating them manually during the final migration. 

How can I do this?
I assume you know the path of the link you need to change and that's all?
If so this should work for you.
Note that I have put comments in place of any error/success reporting, which you can add if you want it.

It also assumes you know how to integrate this into the migration.
This shows the menu link saving only.
I can expand to show migrate integration although that is really a separate question.

Note: The paths used for menu items are drupal internal paths, not path aliases. To convert a path alias to an internal path you can use drupal_get_normal_path().

// Variables used below. Set these to the values you need.
// The current path of the link.
$path = '';
// The menu the link is in. If you don't want to be menu specific remove the menu_name part of the SQL below.
$menu = '';
// The new path for the link.
$new_path = '';

// Get the menu link ID for the given path in the given menu.
// If you donb't know the menu it is in you can omit that part of the query.
// This also handles the case where there are multiple menu links for the same
// path.
$mlids = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu", array(':path' =&gt; $path, ':menu' =&gt; $menu))-&gt;fetchCol();
if ($mlids) {
  // Loop through the matching menu items and update them.
  foreach ($mlids as $mlid) {
    if ($menu_link = menu_link_load($mlid)) {
      // Set the new menu link data.
      $menu_link['link_path'] = $new_path;
      // Save the menu link.
      if (!menu_link_save($menu_link)) {
        // There was an error saving the link.
      }
      else {
        // The link has been saved successfully.
      }
    }
    else {
      // Menu link $mlid not found.
    }
  }
}
else {
  // No menu links were found for this $path.
}