Assign a node to an organic group Programmatically assign a node to an organic group is following my previous question which I have found the solution for Drupal 7, but I am now looking for the same issue in Drupal 6. 

How can I programmatically assign a node to an organic group?

I have tried the following and neither of them worked (assuming $target_group is the group ID that I want the $node to be assigned to).

$node-&gt;og_groups = array($target_group =&gt; $target_group);
node_save($node);




$group = node_load($target_group);
$node-&gt;og_groups[0] = $target_group;
$node-&gt;og_groups_names[0] = $group-&gt;title;


What is the proper way to do this?
You're on the right track.
You also have to add a row to the og_ancestry table. Someone posted sample code for Drupal 6 here.

/**
 * Implementation of hook_nodeapi().
 */
function mymodule_nodeapi(&amp;$node, $op, $arg, $page) {
  switch ($op) {
    case 'insert':
      // let's autocreate a Wiki node for our Top wiki page when we create a Group
      if ($node-&gt;type == "group") {
        global $user;
        include_once (drupal_get_path('module', 'pathauto') .'/pathauto.inc');
        $path = pathauto_cleanstring($node-&gt;title);

        $wiki-&gt;type = "wiki";
        $wiki-&gt;status = 1;
        $wiki-&gt;uid = $user-&gt;uid;
        $wiki-&gt;name = $user-&gt;name;

        $wiki-&gt;title = $node-&gt;title . " Wiki";
        $wiki-&gt;body = t("This is the Wiki for your Community. Any member is allowed to edit this page. Be the first to edit this page by selecting the EDIT tab above and deleting this content and replacing it with your own.");
        $wiki-&gt;path = "wiki/" . $path;
        $wiki-&gt;og_initial_groups[0][$node-&gt;nid];
        $wiki-&gt;og_groups[0] = $node-&gt;nid;
        $wiki-&gt;og_public = 0;
        $wiki-&gt;og_groups_names[0] = $node-&gt;title;

        if ($wiki = node_submit($wiki)) {
          node_save($wiki);
          $sql = "INSERT INTO {og_ancestry} (nid, group_nid) VALUES (%d, %d)";
          db_query($sql, $wiki-&gt;nid, $node-&gt;nid);
        }
      }

      break;    
  }
}