Docs

createOrganizationInvitation()

Creates an OrganizationInvitation for new users to join an organization.

function createOrganizationInvitation(
  params: CreateOrganizationInvitationParams,
): Promise<OrganizationInvitation>
  • Name
    organizationId
    Type
    string
    Description

    The organization ID of the organization a user is being invited to.

  • Name
    inviterUserId
    Type
    string | null
    Description

    The user ID of the user creating the invitation.

  • Name
    emailAddress
    Type
    string
    Description

    The email address to send the invitation to.

  • Name
    role
    Type
    string
    Description

    The role to assign the invited user within the organization.

  • Name
    redirectUrl?
    Type
    string
    Description

    The URL users will land at once the organization invitation has been accepted.

  • Name
    publicMetadata?
    Type
    OrganizationInvitationPublicMetadata
    Description

    Metadata that can be read from both the Frontend API and Backend API, but can be set only from the Backend API.

const organizationId = 'org_123'

const inviterUserId = 'user_123'

const emailAddress = 'testclerk123@clerk.dev'

const role = 'org:member'

const response = await clerkClient.organizations.createOrganizationInvitation({
  organizationId,
  inviterUserId,
  emailAddress,
  role,
})

console.log(response)
/*
_OrganizationInvitation {
  id: 'orginv_123',
  emailAddress: 'testclerk123@clerk.dev',
  role: 'org:member',
  organizationId: 'org_123',
  createdAt: 1705534000014,
  updatedAt: 1705534000014,
  status: 'pending',
  publicMetadata: {},
  privateMetadata: {}
}
*/

Backend API (BAPI) endpoint

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

Feedback

What did you think of this content?

Last updated on