I'm having problem while adding users in organic group. Here I'm trying to add user in organic group called "Supervisor", I'm using following json and Rest api :

Json :
{ "title":"Supervisor",
  "og_group_ref": { "und": [{ "target_id": "1921" }]},
  "field_records": { "und": [{ "value": "5" }]}

Rest api : http://localhost/dev/test/node/1921

but, above json and api is not working, am I using correct json and rest api ?

  • The rest api which you are using will display only the node properties. It will not add the users to the group. Instead of this, you need to create your custom rest service callback and link the og group to the user, since og not providing any rest calls.
    – user15837
    Oct 21 '16 at 11:14
  1. Install this module: https://www.drupal.org/project/og_services
  2. Go to admin/structure/services/list/[MY-ENDPOINT]/resources
  3. Enable at minimum the join resource
  4. Flush all of Drupal's caches
  5. Make a POST call to [MY-ENDPOINT]/og/join/[GROUP-NID]/[USER-UID]
  • Thank you, "og_services" module is working, now I am able add multiple users in any group.
    – user66981
    Oct 26 '16 at 5:51

I think this what you need

 * Implements hook_services_resources
function your_module_name_services_resources() {
  return array(
    'add_user' => array(
      'create' => array(
        'help' => 'Add users to group',
        'callback' => 'your_module_add_user_to_group',
        'access callback' => TRUE,
        'access arguments append' => TRUE,
        'args' => array(
            'name' => 'uid',
            'type' => 'id',
            'description' => 'The uid of the user to add in group',
            'source' => array('data' => 'uid'),
            'optional' => FALSE,

 * Call back to add the user
function your_module_add_user_to_group($uid) {
  $user_account = user_load($uid);
  $og_values = array(
     'entity_type' => 'user',
     'entity' => $user_account,
     'state' => OG_STATE_ACTIVE,
   //This is will add the group to the user.
  og_group('node', $your_group_nid, $og_values);
  return success;

Put this code in your custom module file. And go to "Structure->service->your_end_point->enable 'add_user' resources"

Then call url : http://localhost.com/endpoint/add_user

method: POST

In data field data: uid=595 (pass the user id for whom you need to add the group);

I think this will do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.