Programmatically create a organic group
It's simpler than attaching node as group post:

  &lt;?php
  global $user;
  $node = new stdClass();
  $node-&gt;type = 'group'; // Change this to group node type name.
  $node-&gt;uid = $user-&gt;uid;
  $node-&gt;title = t('Title'); // Change title generation
  $node-&gt;body = t('Body'); // Change body generation
  $node-&gt;og_description = t('Group description'); // Change group description generation
  $node-&gt;og_selective = OG_CLOSED;
  $node-&gt;og_register = OG_REGISTRATION_NEVER;
  $node-&gt;og_directory = OG_DIRECTORY_CHOOSE_FALSE;
  $node-&gt;og_private = 0;
  node_save($node);
  og_insert_group($node);
  og_save_subscription($node-&gt;nid, $node-&gt;uid, array('is_active' =&gt; 1, 'is_admin' =&gt; 1));


(ofcourse you also need to check the return values from alle the three functions)