Skip to content
Ona Docs

GetMembership

client.Groups.Memberships.Get(ctx, body) (*GroupMembershipGetResponse, error)
POST/gitpod.v1.GroupService/GetMembership

Gets a specific membership by group ID and subject.

Use this method to:

  • Check if a user or service account is a member of a group
  • Verify group membership for access control

Examples

  • Check user membership:

    Checks if a user is a member of a specific group.

    groupId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
    subject:
      id: "f53d2330-3795-4c5d-a1f3-453121af9c60"
      principal: PRINCIPAL_USER

Authorization

All organization members can check group membership (transparency model).

ParametersExpand Collapse
body GroupMembershipGetParams
Subject param.Field[Subject]

Subject to check membership for

GroupID param.Field[string]Optional
formatuuid
ReturnsExpand Collapse
type GroupMembershipGetResponse struct{…}
Member GroupMembershipOptional

The membership if found, nil if subject is not a member

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"

GetMembership

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.Get(context.TODO(), gitpod.GroupMembershipGetParams{
    Subject: gitpod.F(shared.SubjectParam{
      ID: gitpod.F("f53d2330-3795-4c5d-a1f3-453121af9c60"),
      Principal: gitpod.F(shared.PrincipalUser),
    }),
    GroupID: gitpod.F("d2c94c27-3b76-4a42-b88c-95a85e392c68"),
  })
  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"
    }
  }
}