createOrganizationMembership method

Future<OrganizationMembership?> createOrganizationMembership(
  1. String organizationId,
  2. CreateOrganizationMembershipRequest createOrganizationMembershipRequest
)

Create a new organization membership

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.

Parameters:

Implementation

Future<OrganizationMembership?> createOrganizationMembership(
  String organizationId,
  CreateOrganizationMembershipRequest createOrganizationMembershipRequest,
) async {
  final response = await createOrganizationMembershipWithHttpInfo(
    organizationId,
    createOrganizationMembershipRequest,
  );
  if (response.statusCode >= HttpStatus.badRequest) {
    throw ApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  // When a remote server returns no body with a status of 204, we shall not decode it.
  // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
  // FormatException when trying to decode an empty string.
  if (response.body.isNotEmpty &&
      response.statusCode != HttpStatus.noContent) {
    return await apiClient.deserializeAsync(
      await _decodeBodyBytes(response),
      'OrganizationMembership',
    ) as OrganizationMembership;
  }
  return null;
}