Programmatically subscribing user to a organic group I need to expose OG memberships within API functions calls and wonder how to programmatically subscribe a user to a group (pending state) and then i need to approve him programmatically and change from pending to member. Im using OG 7.2. 

function ask_membership($uid, $gid){
  ????
}

function approve_membership($uid, $gid){
  ????
}


Any help appreciated
Ok got it working, its still the og_group() function.

function group_membership($type, $gid, $uid){
  $group_type = 'node'; //All our/my groups are of type node
  $entity_type = 'user'; //All our/my members are type users
  $values = array(
    'entity_type' =&gt; 'user',
    'entity' =&gt; $uid,
    'field_name' =&gt; FALSE,
    'state' =&gt; 1,
  );
  $return = FALSE;

    switch ($type){
        case 'subscribe':
          $values['state'] = 2;
          og_group($group_type, $gid, $values);
        $return = 'SUBSCRIBED TO TEAM';
          break;
      case  'approve':
          $values['state'] = 1;
          og_group($group_type, $gid, $values);
        $return = 'APPROVED TO TEAM';
        break;
      case 'delete':
        og_ungroup($group_type, $gid, $entity_type, $uid);
        $return = 'REMOVED FROM TEAM';
        break;
      default:
        $return = 'FALSE TYPE';
        break;
    }

  print json_encode($return); 
}


Not that pretty but it works for now.