Group Users

A GroupUser is a record about membership of a User within a Group.

Creating GroupUsers

GroupUsers can be created via the normal create action. When using the update action, if the GroupUser record does not exist for the given user/group IDs it will be created.

List Group Users

SDK Method

GroupUser.list()

Return Object

GroupUser[]

Authorization Requirement

Available to all authenticated keys or sessions.

Method Arguments

ArgumentDescription
group_id
int64
Group ID. If provided, will return group_users of this group.
user_id
int64
User ID. If provided, will return group_users of this user.

Additional Arguments

Example Request

import GroupUser from 'files.com/lib/models/GroupUser';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  const groupUsers = await GroupUser.list({
    group_id: 1,
  });
  for (const groupUser of groupUsers) {
    // Operate on groupUser
  }
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

Create Group User

SDK Method

GroupUser.create()

Return Object

GroupUser

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

ArgumentDescription
group_id
int64
Required
Group ID to add user to.
user_id
int64
Required
User ID to add to group.
admin
boolean
Is the user a group administrator?

Example Request

import GroupUser from 'files.com/lib/models/GroupUser';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  const groupUser = await GroupUser.create({
    group_id: 1,
    user_id: 1,
  });
  // Operate on groupUser
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

Update Group User

SDK Method

groupUser.update()

Return Object

GroupUser

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

ArgumentDescription
group_id
int64
Required
Group ID to add user to.
user_id
int64
Required
User ID to add to group.
admin
boolean
Is the user a group administrator?

Example Request

import GroupUser from 'files.com/lib/models/GroupUser';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  const groupUser = (await GroupUser.list())[0];
  await groupUser.update({
    group_id: 1,
    user_id: 1,
    admin: false,
  });
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

Delete Group User

SDK Method

groupUser.delete()

Return Object

No return value.

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

ArgumentDescription
group_id
int64
Required
Group ID from which to remove user.
user_id
int64
Required
User ID to remove from group.

Example Request

import GroupUser from 'files.com/lib/models/GroupUser';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  const groupUser = (await GroupUser.list())[0];
  await groupUser.delete({
    group_id: 1,
    user_id: 1,
  });
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

The GroupUser Object

Some of the methods above return a GroupUser object. The attributes of this object are listed below.

AttributeDescription
group_name
string
Group name
group_id
int64
Group ID
user_id
int64
User ID
admin
boolean
Is this user an administrator of this group?
username
string
Username of the user