Set parent for programmatically created menu links
Turns out when setting the parent you don't use the id of the menu_link_content you use the 'menu_link_content:' followed by the uuid of the link. Here's an example of a properly formatted parent field.


  'menu_link_content:0025c274-4db3-4745-b51e-714c998b5a50'


I fixed the code like so

    foreach ($items as $id =&gt; $title) {
        if ($id == '2') {
            $parent = 'menu_link_content:' . $previous_menu_link-&gt;uuid();
        } else {
            $parent == NULL;
        }

        $menu_link = MenuLinkContent::create([
            'title' =&gt; $title,
            'link' =&gt; ['uri' =&gt; 'internal:/node/' . $nid],
            'menu_name' =&gt; $menu_id,
            'expanded' =&gt; true,
            'langcode' =&gt; $langcode,
            'status' =&gt; TRUE,
            'parent' =&gt; $parent,
        ]);

        $menu_link-&gt;save();
        $previous_menu_link = $menu_link;
    }