Skip to content
Ona Docs

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.

    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.

ParametersExpand Collapse
body GroupMembershipNewParams
GroupID param.Field[string]Optional
formatuuid
Subject param.Field[Subject]Optional

Subject to add to the group

ReturnsExpand Collapse
type GroupMembershipNewResponse struct{…}
Member GroupMembershipOptional

GroupMembership represents a subject’s membership in a group

ID stringOptional

Unique identifier for the group membership

formatuuid
AvatarURL stringOptional

Subject’s avatar URL

GroupID stringOptional

Group identifier

formatuuid
Name stringOptional

Subject’s display name

Subject SubjectOptional

Subject (user, runner, environment, service account, etc.)

ID stringOptional

id is the UUID of the subject

formatuuid
Principal PrincipalOptional

Principal is the principal of the subject

One of the following:
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"

CreateMembership

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)
}
{
  "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"
    }
  }
}
Returns Examples
{
  "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"
    }
  }
}