Assigning entity (node) to group (og) programmatically How to assign an entity to a group programmatically? I have referred to this question however it doesn't seems to work:

$values = array(
    'type' =&gt; 'my_type',
    'uid' =&gt; $user-&gt;uid,
    'status' =&gt; 1,
    'comment' =&gt; 1,
    'promote' =&gt; 0,
);
$entity = entity_create('node', $values);
$ewrapper = entity_metadata_wrapper('node', $entity);
$ewrapper-&gt;body-&gt;set(array('value' =&gt; $form_state['values']['body']));
$ewrapper-&gt;save();
$result = og_group('node', $form_state['values']['group_id'], ['entity type' =&gt; 'node', 'entity' =&gt; $ewrapper, 'state' =&gt; OG_STATE_ACTIVE]);
$ewrapper-&gt;save();
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]);