Skip to content
Ona Docs

CreateMembership

groups.memberships.create(MembershipCreateParams**kwargs) -> MembershipCreateResponse
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
group_id: Optional[str]
formatuuid
subject: Optional[Subject]

Subject to add to the group

id: Optional[str]

id is the UUID of the subject

formatuuid
principal: Optional[Principal]

Principal is the principal of the subject

One of the following:
"PRINCIPAL_UNSPECIFIED"
"PRINCIPAL_ACCOUNT"
"PRINCIPAL_USER"
"PRINCIPAL_RUNNER"
"PRINCIPAL_ENVIRONMENT"
"PRINCIPAL_SERVICE_ACCOUNT"
"PRINCIPAL_RUNNER_MANAGER"
ReturnsExpand Collapse
class MembershipCreateResponse:
member: Optional[GroupMembership]

GroupMembership represents a subject’s membership in a group

id: Optional[str]

Unique identifier for the group membership

formatuuid
avatar_url: Optional[str]

Subject’s avatar URL

group_id: Optional[str]

Group identifier

formatuuid
name: Optional[str]

Subject’s display name

subject: Optional[Subject]

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

id: Optional[str]

id is the UUID of the subject

formatuuid
principal: Optional[Principal]

Principal is the principal of the subject

One of the following:
"PRINCIPAL_UNSPECIFIED"
"PRINCIPAL_ACCOUNT"
"PRINCIPAL_USER"
"PRINCIPAL_RUNNER"
"PRINCIPAL_ENVIRONMENT"
"PRINCIPAL_SERVICE_ACCOUNT"
"PRINCIPAL_RUNNER_MANAGER"

CreateMembership

import os
from gitpod import Gitpod

client = Gitpod(
    bearer_token=os.environ.get("GITPOD_API_KEY"),  # This is the default and can be omitted
)
membership = client.groups.memberships.create(
    group_id="d2c94c27-3b76-4a42-b88c-95a85e392c68",
    subject={
        "id": "f53d2330-3795-4c5d-a1f3-453121af9c60",
        "principal": "PRINCIPAL_USER",
    },
)
print(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"
    }
  }
}