- List - Get a list of organization roles
- Create - Create an organization role
- Get - Retrieve an organization role
- Update - Update an organization role
- Delete - Delete an organization role
- AssignPermission - Assign a permission to an organization role
- RemovePermission - Remove a permission from an organization role
This request returns the list of organization roles for the instance.
Results can be paginated using the optional limit and offset query parameters.
The organization roles are ordered by descending creation date.
Most recent roles will be returned first.
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.OrganizationRoles.ListAsync(
orderBy: "-created_at",
limit: 20,
offset: 10
);
// handle response| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
Query |
string | ➖ | Returns organization roles with ID, name, or key that match the given query. Uses exact match for organization role ID and partial match for name and key. |
|
OrderBy |
string | ➖ | Allows to return organization roles in a particular order. At the moment, you can order the returned organization roles by their created_at, name, or key.In order to specify the direction, you can use the +/- symbols prepended in the property to order by.For example, if you want organization roles to be returned in descending order according to their created_at property, you can use -created_at.If you don't use + or -, then + is implied.Defaults to -created_at. |
|
Limit |
long | ➖ | Applies a limit to the number of results returned. Can be used for paginating the results together with offset. |
20 |
Offset |
long | ➖ | Skip the first offset results when paginating.Needs to be an integer greater or equal to zero. To be used in conjunction with limit. |
10 |
| Error Type | Status Code | Content Type |
|---|---|---|
| Clerk.BackendAPI.Models.Errors.ClerkErrors | 400, 401, 403, 422 | application/json |
| Clerk.BackendAPI.Models.Errors.SDKError | 4XX, 5XX | */* |
Creates a new organization role with the given name and permissions for an instance. The key must be unique for the instance and start with the 'org:' prefix, followed by lowercase alphanumeric characters and underscores only. You can optionally provide a description for the role and specify whether it should be included in the initial role set. Organization roles support permissions that can be assigned to control access within the organization.
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Components;
using Clerk.BackendAPI.Models.Operations;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
CreateOrganizationRoleRequestBody req = new CreateOrganizationRoleRequestBody() {
Name = "<value>",
Key = "<key>",
};
var res = await sdk.OrganizationRoles.CreateAsync(req);
// handle response| Parameter | Type | Required | Description |
|---|---|---|---|
request |
CreateOrganizationRoleRequestBody | ✔️ | The request object to use for the request. |
CreateOrganizationRoleResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Clerk.BackendAPI.Models.Errors.ClerkErrors | 400, 401, 402, 403, 404, 422 | application/json |
| Clerk.BackendAPI.Models.Errors.SDKError | 4XX, 5XX | */* |
Use this request to retrieve an existing organization role by its ID.
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.OrganizationRoles.GetAsync(organizationRoleId: "<id>");
// handle response| Parameter | Type | Required | Description |
|---|---|---|---|
OrganizationRoleId |
string | ✔️ | The ID of the organization role |
| Error Type | Status Code | Content Type |
|---|---|---|
| Clerk.BackendAPI.Models.Errors.ClerkErrors | 401, 403, 404 | application/json |
| Clerk.BackendAPI.Models.Errors.SDKError | 4XX, 5XX | */* |
Updates an existing organization role. You can update the name, key, description, and permissions of the role. All parameters are optional - you can update only the fields you want to change. If the role is used as a creator role or domain default role, updating the key will cascade the update to the organization settings.
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Components;
using Clerk.BackendAPI.Models.Operations;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.OrganizationRoles.UpdateAsync(
organizationRoleId: "<id>",
requestBody: new UpdateOrganizationRoleRequestBody() {}
);
// handle response| Parameter | Type | Required | Description |
|---|---|---|---|
OrganizationRoleId |
string | ✔️ | The ID of the organization role to update |
RequestBody |
UpdateOrganizationRoleRequestBody | ✔️ | N/A |
UpdateOrganizationRoleResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Clerk.BackendAPI.Models.Errors.ClerkErrors | 400, 401, 403, 404, 422 | application/json |
| Clerk.BackendAPI.Models.Errors.SDKError | 4XX, 5XX | */* |
Deletes the organization role. The role cannot be deleted if it is currently used as the default creator role, domain default role, assigned to any members, or exists in any invitations.
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.OrganizationRoles.DeleteAsync(organizationRoleId: "<id>");
// handle response| Parameter | Type | Required | Description |
|---|---|---|---|
OrganizationRoleId |
string | ✔️ | The ID of the organization role to delete |
DeleteOrganizationRoleResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Clerk.BackendAPI.Models.Errors.ClerkErrors | 401, 403, 404, 422 | application/json |
| Clerk.BackendAPI.Models.Errors.SDKError | 4XX, 5XX | */* |
Assigns a permission to an organization role
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.OrganizationRoles.AssignPermissionAsync(
organizationRoleId: "<id>",
permissionId: "<id>"
);
// handle response| Parameter | Type | Required | Description |
|---|---|---|---|
OrganizationRoleId |
string | ✔️ | The ID of the organization role |
PermissionId |
string | ✔️ | The ID of the permission to assign |
AssignPermissionToOrganizationRoleResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Clerk.BackendAPI.Models.Errors.ClerkErrors | 401, 403, 404, 409 | application/json |
| Clerk.BackendAPI.Models.Errors.SDKError | 4XX, 5XX | */* |
Removes a permission from an organization role
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Components;
var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.OrganizationRoles.RemovePermissionAsync(
organizationRoleId: "<id>",
permissionId: "<id>"
);
// handle response| Parameter | Type | Required | Description |
|---|---|---|---|
OrganizationRoleId |
string | ✔️ | The ID of the organization role |
PermissionId |
string | ✔️ | The ID of the permission to remove |
RemovePermissionFromOrganizationRoleResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Clerk.BackendAPI.Models.Errors.ClerkErrors | 401, 403, 404, 422 | application/json |
| Clerk.BackendAPI.Models.Errors.SDKError | 4XX, 5XX | */* |