(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
- mergeMetadata - Merge and update metadata for an organization
- uploadLogo - Upload a logo for the organization
- deleteLogo - 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.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.ListOrganizationsRequest;
import com.clerk.backend_api.models.operations.ListOrganizationsResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
ListOrganizationsRequest req = ListOrganizationsRequest.builder()
.build();
ListOrganizationsResponse res = sdk.organizations().list()
.request(req)
.call();
if (res.organizations().isPresent()) {
// handle response
}
}
}
ListOrganizationsResponse
Error Type |
Status Code |
Content Type |
models/errors/ClerkErrors |
400, 403, 422 |
application/json |
models/errors/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.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.CreateOrganizationRequestBody;
import com.clerk.backend_api.models.operations.CreateOrganizationResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
CreateOrganizationRequestBody req = CreateOrganizationRequestBody.builder()
.name("<value>")
.createdBy("<value>")
.build();
CreateOrganizationResponse res = sdk.organizations().create()
.request(req)
.call();
if (res.organization().isPresent()) {
// handle response
}
}
}
CreateOrganizationResponse
Error Type |
Status Code |
Content Type |
models/errors/ClerkErrors |
400, 403, 422 |
application/json |
models/errors/SDKError |
4XX, 5XX |
*/* |
Fetches the organization whose ID or slug matches the provided id_or_slug
URL query parameter.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.GetOrganizationResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
GetOrganizationResponse res = sdk.organizations().get()
.organizationId("<id>")
.includeMembersCount(false)
.call();
if (res.organization().isPresent()) {
// handle response
}
}
}
Parameter |
Type |
Required |
Description |
organizationId |
String |
✔️ |
The ID or slug of the organization |
includeMembersCount |
Optional<Boolean> |
➖ |
Flag to denote whether or not the organization's members count should be included in the response. |
GetOrganizationResponse
Error Type |
Status Code |
Content Type |
models/errors/ClerkErrors |
403, 404 |
application/json |
models/errors/SDKError |
4XX, 5XX |
*/* |
Updates an existing organization
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.UpdateOrganizationRequestBody;
import com.clerk.backend_api.models.operations.UpdateOrganizationResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
UpdateOrganizationResponse res = sdk.organizations().update()
.organizationId("<id>")
.requestBody(UpdateOrganizationRequestBody.builder()
.build())
.call();
if (res.organization().isPresent()) {
// handle response
}
}
}
Parameter |
Type |
Required |
Description |
organizationId |
String |
✔️ |
The ID of the organization to update |
requestBody |
UpdateOrganizationRequestBody |
✔️ |
N/A |
UpdateOrganizationResponse
Error Type |
Status Code |
Content Type |
models/errors/ClerkErrors |
402, 404, 422 |
application/json |
models/errors/SDKError |
4XX, 5XX |
*/* |
Deletes the given organization.
Please note that deleting an organization will also delete all memberships and invitations.
This is not reversible.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.DeleteOrganizationResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
DeleteOrganizationResponse res = sdk.organizations().delete()
.organizationId("<id>")
.call();
if (res.deletedObject().isPresent()) {
// handle response
}
}
}
Parameter |
Type |
Required |
Description |
organizationId |
String |
✔️ |
The ID of the organization to delete |
DeleteOrganizationResponse
Error Type |
Status Code |
Content Type |
models/errors/ClerkErrors |
404 |
application/json |
models/errors/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
.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.MergeOrganizationMetadataRequestBody;
import com.clerk.backend_api.models.operations.MergeOrganizationMetadataResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
MergeOrganizationMetadataResponse res = sdk.organizations().mergeMetadata()
.organizationId("<id>")
.requestBody(MergeOrganizationMetadataRequestBody.builder()
.build())
.call();
if (res.organization().isPresent()) {
// handle response
}
}
}
Parameter |
Type |
Required |
Description |
organizationId |
String |
✔️ |
The ID of the organization for which metadata will be merged or updated |
requestBody |
MergeOrganizationMetadataRequestBody |
✔️ |
N/A |
MergeOrganizationMetadataResponse
Error Type |
Status Code |
Content Type |
models/errors/ClerkErrors |
400, 401, 404, 422 |
application/json |
models/errors/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
.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.UploadOrganizationLogoFile;
import com.clerk.backend_api.models.operations.UploadOrganizationLogoRequestBody;
import com.clerk.backend_api.models.operations.UploadOrganizationLogoResponse;
import java.lang.Exception;
import java.nio.charset.StandardCharsets;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
UploadOrganizationLogoResponse res = sdk.organizations().uploadLogo()
.organizationId("<id>")
.requestBody(UploadOrganizationLogoRequestBody.builder()
.file(UploadOrganizationLogoFile.builder()
.fileName("example.file")
.content("0x0DDEE4e6Ea".getBytes(StandardCharsets.UTF_8))
.build())
.build())
.call();
if (res.organizationWithLogo().isPresent()) {
// handle response
}
}
}
Parameter |
Type |
Required |
Description |
organizationId |
String |
✔️ |
The ID of the organization for which to upload a logo |
requestBody |
UploadOrganizationLogoRequestBody |
✔️ |
N/A |
UploadOrganizationLogoResponse
Error Type |
Status Code |
Content Type |
models/errors/ClerkErrors |
400, 403, 404, 413 |
application/json |
models/errors/SDKError |
4XX, 5XX |
*/* |
Delete the organization's logo.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.DeleteOrganizationLogoResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
DeleteOrganizationLogoResponse res = sdk.organizations().deleteLogo()
.organizationId("<id>")
.call();
if (res.organization().isPresent()) {
// handle response
}
}
}
Parameter |
Type |
Required |
Description |
organizationId |
String |
✔️ |
The ID of the organization for which the logo will be deleted. |
DeleteOrganizationLogoResponse
Error Type |
Status Code |
Content Type |
models/errors/ClerkErrors |
404 |
application/json |
models/errors/SDKError |
4XX, 5XX |
*/* |