(organizations)
Organizations are used to group members under a common entity and provide shared access to resources. https://clerk.com/docs/organizations/overview
- list - Get a list of organizations for an instance
- create - Create an organization
- get - Retrieve an organization by ID or slug
- update - Update an organization
- delete - Delete an organization
- merge_metadata - Merge and update metadata for an organization
- upload_logo - Upload a logo for the organization
- delete_logo - Delete the organization's logo.
This request returns the list of organizations for an instance.
Results can be paginated using the optional limit
and offset
query parameters.
The organizations are ordered by descending creation date.
Most recent organizations will be returned first.
from clerk_backend_api import Clerk
s = Clerk(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.organizations.list(limit=20, offset=10, include_members_count=False, query="clerk", order_by="-name")
if res is not None:
# handle response
pass
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
limit |
Optional[int] | ➖ | Applies a limit to the number of results returned. Can be used for paginating the results together with offset . |
20 |
offset |
Optional[int] | ➖ | 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 |
include_members_count |
Optional[bool] | ➖ | Flag to denote whether the member counts of each organization should be included in the response or not. | false |
query |
Optional[str] | ➖ | Returns organizations with ID, name, or slug that match the given query. Uses exact match for organization ID and partial match for name and slug. |
clerk |
order_by |
Optional[str] | ➖ | Allows to return organizations in a particular order. At the moment, you can order the returned organizations either by their name , created_at or members_count .In order to specify the direction, you can use the +/- symbols prepended in the property to order by.For example, if you want organizations 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 . |
-name |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Error Object | Status Code | Content Type |
---|---|---|
models.ClerkErrors | 400,403,422 | application/json |
models.SDKError | 4xx-5xx | / |
Creates a new organization with the given name for an instance.
In order to successfully create an organization you need to provide the ID of the User who will become the organization administrator.
You can specify an optional slug for the new organization.
If provided, the organization slug can contain only lowercase alphanumeric characters (letters and digits) and the dash "-".
Organization slugs must be unique for the instance.
You can provide additional metadata for the organization and set any custom attribute you want.
Organizations support private and public metadata.
Private metadata can only be accessed from the Backend API.
Public metadata can be accessed from the Backend API, and are read-only from the Frontend API.
The created_by
user will see this as their [active organization] (https://clerk.com/docs/organizations/overview#active-organization)
the next time they create a session, presuming they don't explicitly set a different organization as active before then.
from clerk_backend_api import Clerk
s = Clerk(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.organizations.create(request={
"name": "NewOrg",
"created_by": "user_123",
"private_metadata": {
"internal_code": "ABC123",
},
"public_metadata": {
"public_event": "Annual Summit",
},
"slug": "neworg",
"max_allowed_memberships": 100,
"created_at": "<value>",
})
if res is not None:
# handle response
pass
Parameter | Type | Required | Description |
---|---|---|---|
request |
models.CreateOrganizationRequestBody | ✔️ | The request object to use for the request. |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Error Object | Status Code | Content Type |
---|---|---|
models.ClerkErrors | 400,403,422 | application/json |
models.SDKError | 4xx-5xx | / |
Fetches the organization whose ID or slug matches the provided id_or_slug
URL query parameter.
from clerk_backend_api import Clerk
s = Clerk(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.organizations.get(organization_id="org_123", include_members_count=False)
if res is not None:
# handle response
pass
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
organization_id |
str | ✔️ | The ID or slug of the organization | org_123 |
include_members_count |
Optional[bool] | ➖ | Flag to denote whether or not the organization's members count should be included in the response. | |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Error Object | Status Code | Content Type |
---|---|---|
models.ClerkErrors | 403,404 | application/json |
models.SDKError | 4xx-5xx | / |
Updates an existing organization
from clerk_backend_api import Clerk
s = Clerk(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.organizations.update(organization_id="org_123_update", public_metadata={
}, private_metadata={
}, name="New Organization Name", slug="new-org-slug", max_allowed_memberships=100, admin_delete_enabled=True, created_at="<value>")
if res is not None:
# handle response
pass
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
organization_id |
str | ✔️ | The ID of the organization to update | org_123_update |
public_metadata |
Dict[str, Any] | ➖ | Metadata saved on the organization, that is visible to both your frontend and backend. | {} |
private_metadata |
Dict[str, Any] | ➖ | Metadata saved on the organization that is only visible to your backend. | {} |
name |
OptionalNullable[str] | ➖ | The new name of the organization. May not contain URLs or HTML. |
New Organization Name |
slug |
OptionalNullable[str] | ➖ | The new slug of the organization, which needs to be unique in the instance | new-org-slug |
max_allowed_memberships |
OptionalNullable[int] | ➖ | The maximum number of memberships allowed for this organization | 100 |
admin_delete_enabled |
OptionalNullable[bool] | ➖ | If true, an admin can delete this organization with the Frontend API. | true |
created_at |
Optional[str] | ➖ | A custom date/time denoting when the organization was created, specified in RFC3339 format (e.g. 2012-10-20T07:15:20.902Z ). |
|
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Error Object | Status Code | Content Type |
---|---|---|
models.ClerkErrors | 402,404,422 | application/json |
models.SDKError | 4xx-5xx | / |
Deletes the given organization. Please note that deleting an organization will also delete all memberships and invitations. This is not reversible.
from clerk_backend_api import Clerk
s = Clerk(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.organizations.delete(organization_id="org_321_delete")
if res is not None:
# handle response
pass
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
organization_id |
str | ✔️ | The ID of the organization to delete | org_321_delete |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Error Object | Status Code | Content Type |
---|---|---|
models.ClerkErrors | 404 | application/json |
models.SDKError | 4xx-5xx | / |
Update organization metadata attributes by merging existing values with the provided parameters.
Metadata values will be updated via a deep merge.
Deep meaning that any nested JSON objects will be merged as well.
You can remove metadata keys at any level by setting their value to null
.
from clerk_backend_api import Clerk
s = Clerk(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.organizations.merge_metadata(organization_id="org_12345", public_metadata={
"announcement": "We are opening a new office!",
}, private_metadata={
"internal_use_only": "Future plans discussion.",
})
if res is not None:
# handle response
pass
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
organization_id |
str | ✔️ | The ID of the organization for which metadata will be merged or updated | org_12345 |
public_metadata |
Dict[str, Any] | ➖ | Metadata saved on the organization, that is visible to both your frontend and backend. The new object will be merged with the existing value. |
{ "announcement": "We are opening a new office!" } |
private_metadata |
Dict[str, Any] | ➖ | Metadata saved on the organization that is only visible to your backend. The new object will be merged with the existing value. |
{ "internal_use_only": "Future plans discussion." } |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Error Object | Status Code | Content Type |
---|---|---|
models.ClerkErrors | 400,401,404,422 | application/json |
models.SDKError | 4xx-5xx | / |
Set or replace an organization's logo, by uploading an image file.
This endpoint uses the multipart/form-data
request content type and accepts a file of image type.
The file size cannot exceed 10MB.
Only the following file content types are supported: image/jpeg
, image/png
, image/gif
, image/webp
, image/x-icon
, image/vnd.microsoft.icon
.
from clerk_backend_api import Clerk
s = Clerk(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.organizations.upload_logo(organization_id="org_12345", request_body={
"file": {
"file_name": "your_file_here",
"content": open("<file_path>", "rb"),
"content_type": "<value>",
},
"uploader_user_id": "user_67890",
})
if res is not None:
# handle response
pass
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
organization_id |
str | ✔️ | The ID of the organization for which to upload a logo | org_12345 |
request_body |
Optional[models.UploadOrganizationLogoRequestBody] | ➖ | N/A | |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Error Object | Status Code | Content Type |
---|---|---|
models.ClerkErrors | 400,403,404,413 | application/json |
models.SDKError | 4xx-5xx | / |
Delete the organization's logo.
from clerk_backend_api import Clerk
s = Clerk(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.organizations.delete_logo(organization_id="org_12345")
if res is not None:
# handle response
pass
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
organization_id |
str | ✔️ | The ID of the organization for which the logo will be deleted. | org_12345 |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Error Object | Status Code | Content Type |
---|---|---|
models.ClerkErrors | 404 | application/json |
models.SDKError | 4xx-5xx | / |