Click or drag to resize

Example 2: Add users to a workspace

This example adds a user to a Workspace. It requires three separate method calls. (Note the different permissions required for each step).

Create Workspace (can only be done by an organization admin).

This returns a RoomsJson object that represents the room that was created.

C#
Resource.Workspaces workspaces = apiSession.GetWorkspacesResource();

// Create the JSON object needed for the method call, and set its values.
CreateRoomJson createRoomJson = new CreateRoomJson
{
    Name = name,
    Description = description,
    Administrators = administrators
 };

// Call the method, and get a JSON object back
RoomJson roomJson = workspaces.CreateRoomV30(createRoomJson);
Create new room group (can only be done by a Workspace admin)
C#
Resource.Workspaces workspaces = apiSession.GetWorkspacesResource();

// Create a JSON object the represents the new group and set its values
PermittedEntityFromUserJson permittedEntityFromUserJson =
    new PermittedEntityFromUserJson
    {
        Address = groupName,
        EntityType = EntityType.GROUP
    };

// Create a new permissions JSON with default values
PermissionFromUserJson permissionFromUserJson = new PermissionFromUserJson();

// The JSON object needed for the resource method call
AddEntityVdrJson addEntityVdrJson = new AddEntityVdrJson
{
    PermittedEntity = permittedEntityFromUserJson,
    NewPermissions = permissionFromUserJson
};

// Make the call to the Rooms resource and return "success"
return workspaces.AddEntityV30(workspaceId, addEntityVdrJson);
Add members (users) to group
C#
Resource.Workspaces workspaces = apiSession.GetWorkspacesResource();

List<AddMemberToGroupJson> memberList = new List<AddMemberToGroupJson>();

// Loop through the List<String> userAddresses 
foreach (string currentAddress in userAddresses)
{
    PermittedEntityFromUserJson currentEntity = new PermittedEntityFromUserJson
    {
        Address = currentAddress,
        EntityType = EntityType.USER
    };

    //make a AddMemberToGroupJson for each user
    AddMemberToGroupJson currentMemberJson = new AddMemberToGroupJson
    {
        Entity = currentEntity
    };

    memberList.Add(currentMemberJson);
}

// Set the group name to be a string and roomId is the integer identifying the room
AddMembersToGroupWithGroupJson groupMemberJson = new AddMembersToGroupWithGroupJson
{
    MembersList = memberList,
    RoomId = roomId,
    GroupName = groupName
};

// Make the call to the Rooms resource and return "success"
string result = workspaces.AddMembersToGroupV30(groupMemberJson);