- create - Create a new organization membership
- list - Get a list of all members of an organization
- update - Update an organization membership
- delete - Remove a member from an organization
- updateMetadata - Merge and update organization membership metadata
Adds a user as a member to the given organization. Only users in the same instance as the organization can be added as members.
This organization will be the user's [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.CreateOrganizationMembershipRequestBody;
import com.clerk.backend_api.models.operations.CreateOrganizationMembershipResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
CreateOrganizationMembershipResponse res = sdk.organizationMemberships().create()
.organizationId("<id>")
.requestBody(CreateOrganizationMembershipRequestBody.builder()
.userId("<id>")
.role("<value>")
.build())
.call();
if (res.organizationMembership().isPresent()) {
System.out.println(res.organizationMembership().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
organizationId |
String | ✔️ | The ID of the organization where the new membership will be created |
requestBody |
CreateOrganizationMembershipRequestBody | ✔️ | N/A |
CreateOrganizationMembershipResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ClerkErrors | 400, 403, 404, 422 | application/json |
| models/errors/SDKError | 4XX, 5XX | */* |
Retrieves all user memberships for the given 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.ListOrganizationMembershipsRequest;
import com.clerk.backend_api.models.operations.ListOrganizationMembershipsResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
ListOrganizationMembershipsRequest req = ListOrganizationMembershipsRequest.builder()
.organizationId("<id>")
.lastActiveAtBefore(1700690400000L)
.lastActiveAtAfter(1700690400000L)
.createdAtBefore(1730160000000L)
.createdAtAfter(1730160000000L)
.build();
ListOrganizationMembershipsResponse res = sdk.organizationMemberships().list()
.request(req)
.call();
if (res.organizationMemberships().isPresent()) {
System.out.println(res.organizationMemberships().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
request |
ListOrganizationMembershipsRequest | ✔️ | The request object to use for the request. |
ListOrganizationMembershipsResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ClerkErrors | 401, 422 | application/json |
| models/errors/SDKError | 4XX, 5XX | */* |
Updates the properties of an existing organization membership
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.UpdateOrganizationMembershipRequestBody;
import com.clerk.backend_api.models.operations.UpdateOrganizationMembershipResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
UpdateOrganizationMembershipResponse res = sdk.organizationMemberships().update()
.organizationId("<id>")
.userId("<id>")
.requestBody(UpdateOrganizationMembershipRequestBody.builder()
.role("<value>")
.build())
.call();
if (res.organizationMembership().isPresent()) {
System.out.println(res.organizationMembership().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
organizationId |
String | ✔️ | The ID of the organization to which this membership belongs |
userId |
String | ✔️ | The ID of the user to which this membership belongs |
requestBody |
UpdateOrganizationMembershipRequestBody | ✔️ | N/A |
UpdateOrganizationMembershipResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ClerkErrors | 404, 422 | application/json |
| models/errors/SDKError | 4XX, 5XX | */* |
Removes the given membership from the 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.DeleteOrganizationMembershipResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
DeleteOrganizationMembershipResponse res = sdk.organizationMemberships().delete()
.organizationId("<id>")
.userId("<id>")
.call();
if (res.organizationMembership().isPresent()) {
System.out.println(res.organizationMembership().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
organizationId |
String | ✔️ | The ID of the organization to which this membership belongs |
userId |
String | ✔️ | The ID of the user to which this membership belongs |
DeleteOrganizationMembershipResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ClerkErrors | 401, 404, 422 | application/json |
| models/errors/SDKError | 4XX, 5XX | */* |
Update an organization membership's metadata attributes by merging existing values with the provided parameters.
Metadata values will be updated via a deep merge. Deep means 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.UpdateOrganizationMembershipMetadataResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
UpdateOrganizationMembershipMetadataResponse res = sdk.organizationMemberships().updateMetadata()
.organizationId("<id>")
.userId("<id>")
.call();
if (res.organizationMembership().isPresent()) {
System.out.println(res.organizationMembership().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
organizationId |
String | ✔️ | The ID of the organization to which this membership belongs |
userId |
String | ✔️ | The ID of the user to which this membership belongs |
requestBody |
Optional<UpdateOrganizationMembershipMetadataRequestBody> | ➖ | N/A |
UpdateOrganizationMembershipMetadataResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ClerkErrors | 400, 404, 422 | application/json |
| models/errors/SDKError | 4XX, 5XX | */* |