How to assign nodes to an organic group in code How can I assign a node to an organic group in code?
After consulting following page 


http://www.barnettech.com/content/adding-node-organic-group-programmatically
Programmatically assign a node to an organic group


And de OG API I ended up with this code, but it throws an error 'The website encountered an unexpected error. Please try again later.'

$node = node_load(5827);
$values = array('entity type' =&gt; 'node', 'entity' =&gt; $node, 'field_name' =&gt;'og_group_ref');
og_group('node', 3, $values);
node_save($node);


More info:
OG-7.2.7
Found out removing the last line from the snippet 'node_save($node)' and the above type error was the reason for my problem. Thanks for the support.