Skip to main content
Docs

createOrganizationMembership()

Creates a membership to an organization for a user directly (circumventing the need for an invitation). Returns a OrganizationMembership object.

function createOrganizationMembership(
  params: CreateOrganizationMembershipParams,
): Promise<OrganizationMembership>
  • Name
    organizationId
    Type
    string
    Description

    The ID of the organization the user is being added to.

  • Name
    userId
    Type
    string
    Description

    The ID of the user to be added to the organization.

  • Name
    role
    Type
    string
    Description

    The role to assign the added user within the organization.

Note

Importing clerkClient varies based on your framework. Refer to the Backend SDK overview for usage details, including guidance on how to access the userId and other properties.

In the following example, an OrganizationMembership is created for a user with the role org:member.

const organizationId = 'org_123'

const userId = 'user_123'

const role = 'org:member'

const response = await clerkClient.organizations.createOrganizationMembership({
  organizationId,
  userId,
  role,
})

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint POST/organizations/{organization_id}/memberships. See the BAPI reference for more information.

Feedback

What did you think of this content?

Last updated on