Box Developer Documentation

Join BoxWorks 2024 to discover what's possible with content and AI!

Register now!

Add user to group

post
https://api.box.com/2.0
/group_memberships

Creates a group membership. Only users with admin-level permissions will be able to use this API.

Request

bearer [ACCESS_TOKEN]
application/json

Query Parameters

string arrayin queryoptional
id,type,name

A comma-separated list of attributes to include in the response. This can be used to request fields that are not normally returned in a standard response.

Be aware that specifying this parameter will have the effect that none of the standard fields are returned in the response unless explicitly specified, instead only fields for the mini representation are returned, additional to the fields requested.

Request Body

associative arrayin body

Custom configuration for the permissions an admin if a group will receive. This option has no effect on members with a role of member.

Setting these permissions overwrites the default access levels of an admin.

Specifying a value of null for this object will disable all configurable permissions. Specifying permissions will set them accordingly, omitted permissions will be enabled by default.

booleanin bodyoptional
true

A key value pair of custom permissions.

objectin body

The group to add the user to.

stringin bodyrequired
"4545523"

The ID of the group to add the user to

stringin bodyoptional
"member"

The role of the user in the group.

Value is one of member,admin

objectin body

The user to add to the group.

stringin bodyrequired
"1434325"

The ID of the user to add to the group

Response

application/jsonGroup membership

Returns a new group membership object.

application/jsonClient error

Returns an error when the user cannot be added to a group.

  • forbidden_by_policy: Adding a user to a group is forbidden due to information barrier restrictions.
application/jsonClient error

An unexpected client error.

post
Add user to group
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -i -X POST "https://api.box.com/2.0/group_memberships" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "content-type: application/json" \
     -d '{
       "user": {
         "id": "1434325"
       },
       "group": {
         "id": "4545523"
       }
     }'
TypeScript Gen
await client.memberships.createGroupMembership({
  user: { id: user.id } satisfies CreateGroupMembershipRequestBodyUserField,
  group: { id: group.id } satisfies CreateGroupMembershipRequestBodyGroupField,
} satisfies CreateGroupMembershipRequestBody);
Python Gen
client.memberships.create_group_membership(
    CreateGroupMembershipUser(id=user.id), CreateGroupMembershipGroup(id=group.id)
)
.NET Gen
await client.Memberships.CreateGroupMembershipAsync(requestBody: new CreateGroupMembershipRequestBody(user: new CreateGroupMembershipRequestBodyUserField(id: user.Id), group: new CreateGroupMembershipRequestBodyGroupField(id: group.Id)));
Swift Gen (Beta)
try await client.memberships.createGroupMembership(requestBody: CreateGroupMembershipRequestBody(user: CreateGroupMembershipRequestBodyUserField(id: user.id), group: CreateGroupMembershipRequestBodyGroupField(id: group.id)))
Java
BoxGroup group = new BoxGroup(api, "groupID");
BoxUser user = new BoxUser(api, "userID");
BoxGroupMembership.Info groupMembershipInfo = group.addMembership(user);
Python
user = client.user('1111')
membership = client.group(group_id='11111').add_member(user)
print(f'Added {membership.user.name} to the {membership.group.name} group!')
.NET
var requestParams = new BoxGroupMembershipRequest()
{
    User = new BoxRequestEntity()
    {
        Id = "22222"
    },
    Group = new BoxGroupRequest()
    {
        Id = "11111"
    }
};
BoxGroupMembership membership = await client.GroupsManager.AddMemberToGroupAsync(requestParams);
Node
var groupID = '11111';
var userID = '22222';
client.groups.addUser(groupID, userID, {role: client.groups.userRoles.MEMBER})
	.then(membership => {
		/* membership -> {
			type: 'group_membership',
			id: '33333',
			user: 
			{ type: 'user',
				id: '22222',
				name: 'Alison Wonderland',
				login: 'alice@example.com' },
			group: { type: 'group', id: '11111', name: 'Employees' },
			role: 'member',
			configurable_permissions: 
			{ can_run_reports: false,
				can_instant_login: false,
				can_create_accounts: false,
				can_edit_accounts: false } }
		*/
	});
iOS
client.createMembership(userId: "54321", groupId: "11111", role: .admin, configurablePermission: .value(ConfigurablePermissionData(canRunReports: true, canInstantLogin: true, canCreateAccounts: false, canEditAccounts: true))) { 
(result: Result<GroupMembership, BoxSDKError>) in
    guard case let .success(membership) = result else {
        print("Error creating group membership")
        return
    }

    print("Group membership for group \(membership.group?.name) was created")
}

Response Example

{
  "id": "11446498",
  "type": "group_membership",
  "created_at": "2012-12-12T10:53:43-08:00",
  "group": {
    "id": "11446498",
    "type": "group",
    "group_type": "managed_group",
    "name": "Support"
  },
  "modified_at": "2012-12-12T10:53:43-08:00",
  "role": "member",
  "user": {
    "id": "11446498",
    "type": "user",
    "login": "ceo@example.com",
    "name": "Aaron Levie"
  }
}