Skip to content

Latest commit

 

History

History
272 lines (177 loc) · 31.1 KB

File metadata and controls

272 lines (177 loc) · 31.1 KB

OrganizationMembershipsSDK

(organization_memberships)

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
  • update_metadata - Merge and update organization membership metadata
  • get_all - Get a list of all organization memberships within an instance.

create

Adds a user as a member to the given organization.

Example Usage

from clerk_backend_api import Clerk

with Clerk(
    bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as clerk:

    res = clerk.organization_memberships.create(organization_id="org_123", user_id="user_456", role="admin")

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
organization_id str ✔️ The ID of the organization where the new membership will be created org_123
user_id str ✔️ The ID of the user that will be added as a member in the organization. user_456
role str ✔️ The role that the new member will have in the organization. admin
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.OrganizationMembership

Errors

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

list

Retrieves all user memberships for the given organization

Example Usage

from clerk_backend_api import Clerk

with Clerk(
    bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as clerk:

    res = clerk.organization_memberships.list(organization_id="org_789", limit=20, offset=10, order_by="+created_at")

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
organization_id str ✔️ The organization ID. org_789
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
order_by Optional[str] Sorts organizations memberships by phone_number, email_address, created_at, first_name, last_name or username.
By prepending one of those values with + or -,
we can choose to sort in ascending (ASC) or descending (DESC) order."
+created_at
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.OrganizationMemberships

Errors

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

update

Updates the properties of an existing organization membership

Example Usage

from clerk_backend_api import Clerk

with Clerk(
    bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as clerk:

    res = clerk.organization_memberships.update(organization_id="org_12345", user_id="user_67890", role="admin")

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
organization_id str ✔️ The ID of the organization the membership belongs to org_12345
user_id str ✔️ The ID of the user that this membership belongs to user_67890
role str ✔️ The new role of the given membership. admin
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.OrganizationMembership

Errors

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

delete

Removes the given membership from the organization

Example Usage

from clerk_backend_api import Clerk

with Clerk(
    bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as clerk:

    res = clerk.organization_memberships.delete(organization_id="org_12345", user_id="user_67890")

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
organization_id str ✔️ The ID of the organization the membership belongs to org_12345
user_id str ✔️ The ID of the user that this membership belongs to user_67890
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.OrganizationMembership

Errors

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

update_metadata

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

from clerk_backend_api import Clerk

with Clerk(
    bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as clerk:

    res = clerk.organization_memberships.update_metadata(organization_id="org_123456", user_id="user_654321", public_metadata={

    }, private_metadata={

    })

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
organization_id str ✔️ The ID of the organization the membership belongs to org_123456
user_id str ✔️ The ID of the user that this membership belongs to user_654321
public_metadata Dict[str, Any] Metadata saved on the organization membership, that is visible to both your frontend and backend.
The new object will be merged with the existing value.
{}
private_metadata Dict[str, Any] Metadata saved on the organization membership that is only visible to your backend.
The new object will be merged with the existing value.
{}
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.OrganizationMembership

Errors

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

get_all

Retrieves all organization user memberships for the given instance.

Example Usage

from clerk_backend_api import Clerk

with Clerk(
    bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as clerk:

    res = clerk.organization_memberships.get_all(limit=20, offset=10, order_by="<value>")

    assert res is not None

    # Handle response
    print(res)

Parameters

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
order_by Optional[str] Sorts organizations memberships by phone_number, email_address, created_at, first_name, last_name or username.
By prepending one of those values with + or -,
we can choose to sort in ascending (ASC) or descending (DESC) order.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.OrganizationMemberships

Errors

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