- 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.
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
}| Parameter | Type | Required | Description |
|---|---|---|---|
organizationId |
string | ✔️ | The ID of the organization where the new membership will be created |
requestBody |
Operations\CreateOrganizationMembershipRequestBody | ✔️ | N/A |
?Operations\CreateOrganizationMembershipResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\ClerkErrors | 400, 403, 404, 422 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |
Retrieves all user memberships for the given organization
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
}| Parameter | Type | Required | Description |
|---|---|---|---|
$request |
Operations\ListOrganizationMembershipsRequest | ✔️ | The request object to use for the request. |
?Operations\ListOrganizationMembershipsResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\ClerkErrors | 401, 422 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |
Updates the properties of an existing organization membership
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
}| 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 |
?Operations\UpdateOrganizationMembershipResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\ClerkErrors | 404, 422 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |
Removes the given membership from the organization
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
}| 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 |
?Operations\DeleteOrganizationMembershipResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\ClerkErrors | 401, 404, 422 | application/json |
| Errors\SDKException | 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.
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
}| 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 |
?Operations\UpdateOrganizationMembershipMetadataResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\ClerkErrors | 400, 404, 422 | application/json |
| Errors\SDKException | 4XX, 5XX | */* |