## CreateMembership `client.Groups.Memberships.New(ctx, body) (*GroupMembershipNewResponse, error)` **post** `/gitpod.v1.GroupService/CreateMembership` Creates a membership for a user in a group. Use this method to: - Add users to groups - Grant group-based permissions to users ### Examples - Add a user to a group: Creates a membership for a user in a group. ```yaml groupId: "d2c94c27-3b76-4a42-b88c-95a85e392c68" subject: id: "f53d2330-3795-4c5d-a1f3-453121af9c60" principal: PRINCIPAL_USER ``` ### Authorization Requires `org:admin` permission on the organization or `group:admin` permission on the specific group. ### Parameters - `body GroupMembershipNewParams` - `GroupID param.Field[string]` - `Subject param.Field[Subject]` Subject to add to the group ### Returns - `type GroupMembershipNewResponse struct{…}` - `Member GroupMembership` GroupMembership represents a subject's membership in a group - `ID string` Unique identifier for the group membership - `AvatarURL string` Subject's avatar URL - `GroupID string` Group identifier - `Name string` Subject's display name - `Subject Subject` Subject (user, runner, environment, service account, etc.) - `ID string` id is the UUID of the subject - `Principal Principal` Principal is the principal of the subject - `const PrincipalUnspecified Principal = "PRINCIPAL_UNSPECIFIED"` - `const PrincipalAccount Principal = "PRINCIPAL_ACCOUNT"` - `const PrincipalUser Principal = "PRINCIPAL_USER"` - `const PrincipalRunner Principal = "PRINCIPAL_RUNNER"` - `const PrincipalEnvironment Principal = "PRINCIPAL_ENVIRONMENT"` - `const PrincipalServiceAccount Principal = "PRINCIPAL_SERVICE_ACCOUNT"` - `const PrincipalRunnerManager Principal = "PRINCIPAL_RUNNER_MANAGER"` ### Example ```go package main import ( "context" "fmt" "github.com/gitpod-io/gitpod-sdk-go" "github.com/gitpod-io/gitpod-sdk-go/option" "github.com/gitpod-io/gitpod-sdk-go/shared" ) func main() { client := gitpod.NewClient( option.WithBearerToken("My Bearer Token"), ) membership, err := client.Groups.Memberships.New(context.TODO(), gitpod.GroupMembershipNewParams{ GroupID: gitpod.F("d2c94c27-3b76-4a42-b88c-95a85e392c68"), Subject: gitpod.F(shared.SubjectParam{ ID: gitpod.F("f53d2330-3795-4c5d-a1f3-453121af9c60"), Principal: gitpod.F(shared.PrincipalUser), }), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", membership.Member) } ``` #### Response ```json { "member": { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "avatarUrl": "avatarUrl", "groupId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "name": "name", "subject": { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "principal": "PRINCIPAL_UNSPECIFIED" } } } ```