Skip to content

Latest commit

 

History

History
300 lines (215 loc) · 18.3 KB

File metadata and controls

300 lines (215 loc) · 18.3 KB

OrganizationMemberships

Overview

Available Operations

  • 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

create

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.

Example Usage

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());
        }
    }
}

Parameters

Parameter Type Required Description
organizationId String ✔️ The ID of the organization where the new membership will be created
requestBody CreateOrganizationMembershipRequestBody ✔️ N/A

Response

CreateOrganizationMembershipResponse

Errors

Error Type Status Code Content Type
models/errors/ClerkErrors 400, 403, 404, 422 application/json
models/errors/SDKError 4XX, 5XX */*

list

Retrieves all user memberships for the given organization

Example Usage

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());
        }
    }
}

Parameters

Parameter Type Required Description
request ListOrganizationMembershipsRequest ✔️ The request object to use for the request.

Response

ListOrganizationMembershipsResponse

Errors

Error Type Status Code Content Type
models/errors/ClerkErrors 401, 422 application/json
models/errors/SDKError 4XX, 5XX */*

update

Updates the properties of an existing organization membership

Example Usage

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());
        }
    }
}

Parameters

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

Response

UpdateOrganizationMembershipResponse

Errors

Error Type Status Code Content Type
models/errors/ClerkErrors 404, 422 application/json
models/errors/SDKError 4XX, 5XX */*

delete

Removes the given membership from the organization

Example Usage

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());
        }
    }
}

Parameters

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

Response

DeleteOrganizationMembershipResponse

Errors

Error Type Status Code Content Type
models/errors/ClerkErrors 401, 404, 422 application/json
models/errors/SDKError 4XX, 5XX */*

updateMetadata

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.

Example Usage

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());
        }
    }
}

Parameters

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

Response

UpdateOrganizationMembershipMetadataResponse

Errors

Error Type Status Code Content Type
models/errors/ClerkErrors 400, 404, 422 application/json
models/errors/SDKError 4XX, 5XX */*