Assigning entity (node) to group (og) programmatically
According to the API documentation, my code was missing an underscore character, and I should pass in the entity. So instead of

$result = og_group('node', $form_state['values']['group_id'], ['entity type' =&gt; 'node', 'entity' =&gt; $ewrapper, 'state' =&gt; OG_STATE_ACTIVE]);


it should be

$result = og_group('node', $form_state['values']['group_id'], ['entity_type' =&gt; 'node', 'entity' =&gt; $entity-&gt;nid, 'state' =&gt; OG_STATE_ACTIVE]);