Skip to content

Latest commit

 

History

History
288 lines (198 loc) · 16.1 KB

File metadata and controls

288 lines (198 loc) · 16.1 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

declare(strict_types=1);

require 'vendor/autoload.php';

use Clerk\Backend;
use Clerk\Backend\Models\Operations;

$sdk = Backend\ClerkBackend::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();

$requestBody = new Operations\CreateOrganizationMembershipRequestBody(
    userId: '<id>',
    role: '<value>',
);

$response = $sdk->organizationMemberships->create(
    organizationId: '<id>',
    requestBody: $requestBody

);

if ($response->organizationMembership !== null) {
    // handle response
}

Parameters

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

Response

?Operations\CreateOrganizationMembershipResponse

Errors

Error Type Status Code Content Type
Errors\ClerkErrors 400, 403, 404, 422 application/json
Errors\SDKException 4XX, 5XX */*

list

Retrieves all user memberships for the given organization

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Clerk\Backend;
use Clerk\Backend\Models\Operations;

$sdk = Backend\ClerkBackend::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();

$request = new Operations\ListOrganizationMembershipsRequest(
    organizationId: '<id>',
    lastActiveAtBefore: 1700690400000,
    lastActiveAtAfter: 1700690400000,
    createdAtBefore: 1730160000000,
    createdAtAfter: 1730160000000,
);

$response = $sdk->organizationMemberships->list(
    request: $request
);

if ($response->organizationMemberships !== null) {
    // handle response
}

Parameters

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

Response

?Operations\ListOrganizationMembershipsResponse

Errors

Error Type Status Code Content Type
Errors\ClerkErrors 401, 422 application/json
Errors\SDKException 4XX, 5XX */*

update

Updates the properties of an existing organization membership

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Clerk\Backend;
use Clerk\Backend\Models\Operations;

$sdk = Backend\ClerkBackend::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();

$requestBody = new Operations\UpdateOrganizationMembershipRequestBody(
    role: '<value>',
);

$response = $sdk->organizationMemberships->update(
    organizationId: '<id>',
    userId: '<id>',
    requestBody: $requestBody

);

if ($response->organizationMembership !== null) {
    // handle response
}

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 Operations\UpdateOrganizationMembershipRequestBody ✔️ N/A

Response

?Operations\UpdateOrganizationMembershipResponse

Errors

Error Type Status Code Content Type
Errors\ClerkErrors 404, 422 application/json
Errors\SDKException 4XX, 5XX */*

delete

Removes the given membership from the organization

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Clerk\Backend;

$sdk = Backend\ClerkBackend::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();



$response = $sdk->organizationMemberships->delete(
    organizationId: '<id>',
    userId: '<id>'

);

if ($response->organizationMembership !== null) {
    // handle response
}

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

?Operations\DeleteOrganizationMembershipResponse

Errors

Error Type Status Code Content Type
Errors\ClerkErrors 401, 404, 422 application/json
Errors\SDKException 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

declare(strict_types=1);

require 'vendor/autoload.php';

use Clerk\Backend;

$sdk = Backend\ClerkBackend::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();



$response = $sdk->organizationMemberships->updateMetadata(
    organizationId: '<id>',
    userId: '<id>',
    requestBody: $requestBody

);

if ($response->organizationMembership !== null) {
    // handle response
}

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 ?Operations\UpdateOrganizationMembershipMetadataRequestBody N/A

Response

?Operations\UpdateOrganizationMembershipMetadataResponse

Errors

Error Type Status Code Content Type
Errors\ClerkErrors 400, 404, 422 application/json
Errors\SDKException 4XX, 5XX */*