Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev

createOrganizationInvitation()

Creates an OrganizationInvitation for new users to join an organization.

function createOrganizationInvitation: (params: CreateOrganizationInvitationParams) => Promise<OrganizationInvitation>;

CreateOrganizationInvitationParams

NameTypeDescription
organizationIdstringThe organization ID of the organization a user is being invited to.
inviterUserIdstringThe user ID of the user creating the invitation.
emailAddressstringThe email address to send the invitation to.
rolestringThe role to assign the invited user within the organization.
redirectUrl?stringThe URL users will land at once the organization invitation has been accepted.
publicMetadata?Record<string, unknown>Metadata saved on the invitation that is visible to both your Frontend and Backend APIs.

createOrganizationInvitation() example

const organizationId = 'org_2ZUtbk2yvnFGItdeze1ivCh3uqh'; const inviterUserId = 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56'; 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_2b6SO8VwBMDn2IMYn0xqiaSxVpN', emailAddress: 'testclerk123@clerk.dev', role: 'org:member', organizationId: 'org_2ZUtbk2yvnFGItdeze1ivCh3uqh', 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(opens in a new tab) for more details.

What did you think of this content?

Clerk © 2024