> ## Documentation Index
> Fetch the complete documentation index at: https://ona.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Role

> Manages organization membership and roles by setting a user's role within the organization.

`Unary` · [`Organizations`](https://ona.com/docs/api-reference/generated/organization/overview)

Manages organization membership and roles by setting a user's role within the organization.

Use this method to:

* Promote members to admin role
* Change member permissions
* Demote admins to regular members

### Examples

* Promote to admin:

  Makes a user an organization administrator.

  ```yaml theme={null}
  organizationId: "b0e12f6c-4c67-429d-a4a6-d9838b5da047"
  userId: "f53d2330-3795-4c5d-a1f3-453121af9c60"
  role: ORGANIZATION_ROLE_ADMIN
  ```

* Change to member:

  Changes a user's role to regular member.

  ```yaml theme={null}
  organizationId: "b0e12f6c-4c67-429d-a4a6-d9838b5da047"
  userId: "f53d2330-3795-4c5d-a1f3-453121af9c60"
  role: ORGANIZATION_ROLE_MEMBER
  ```

## Endpoint

```text theme={null}
POST /api/gitpod.v1.OrganizationService/SetRole
```

Send a Bearer token as described in [Authentication](https://ona.com/docs/api-reference.md#authenticate-requests). If your organization uses a custom management-plane domain, replace `https://app.ona.com` with that domain.

## Request example

```bash cURL theme={null}
export ONA_HOST=https://app.ona.com
export ONA_API_KEY=<your-token>

curl --request POST \
  --url "$ONA_HOST/api/gitpod.v1.OrganizationService/SetRole" \
  --header "Authorization: Bearer $ONA_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "organizationId": "<organization-id>",
  "userId": "<user-id>"
}'
```

```python Python theme={null}
import gitpod.v1.organization_pb2 as organization_pb2
from ona_sdk import create_client_from_env

ona = create_client_from_env()
request = organization_pb2.SetRoleRequest(
    organization_id="<organization-id>",
    user_id="<user-id>",
)
response = ona.services.organization.set_role(request)
print(response)
```

```typescript TypeScript theme={null}
import { create } from "@bufbuild/protobuf";
import { createClientFromEnv } from "@gitpod/sdk";
import { SetRoleRequestSchema } from "@gitpod/sdk/gitpod/v1/organization_pb";

async function main() {
  const ona = createClientFromEnv();
  const request = create(SetRoleRequestSchema, {
    organizationId: "<organization-id>",
    userId: "<user-id>",
  });
  const response = await ona.services.organization.setRole(request);
  console.log(response);
}

main().catch(console.error);
```

```go Go theme={null}
package main

import (
	"context"
	"fmt"
	"log"

	"connectrpc.com/connect"
	"github.com/gitpod-io/gitpod-sdk-go/sdk"
	gitpodpb "github.com/gitpod-io/gitpod-sdk-go/v1"
)

func main() {
	ona, err := sdk.NewFromEnv()
	if err != nil {
		log.Fatal(err)
	}

	request := connect.NewRequest(&gitpodpb.SetRoleRequest{
		OrganizationId: "<organization-id>",
		UserId: "<user-id>",
	})
	response, err := ona.Services.Organization.SetRole(context.Background(), request)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(response.Msg)
}
```

```json Request body theme={null}
{
  "organizationId": "<organization-id>",
  "userId": "<user-id>"
}
```

## Request

`gitpod.v1.SetRoleRequest`

| Field | Type | Required | Description |
| - | - | - | - |
| `organizationId` | string | Yes | Constraints: `required=true, string.uuid=true`. |
| `userId` | string | Yes | Constraints: `required=true, string.uuid=true`. |
| `role` | [OrganizationRole](#enum-gitpod-v1-organization-role) | No | |

## Response

`gitpod.v1.SetRoleResponse`

This message has no fields.

## Related types

> [accordion] OrganizationRole
>
> | Value | Number | Description |
> | - | -: | - |
> | `ORGANIZATION_ROLE_UNSPECIFIED` | 0 | |
> | `ORGANIZATION_ROLE_ADMIN` | 1 | |
> | `ORGANIZATION_ROLE_MEMBER` | 2 | |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.