Invite an application user
An administrator needs to add a person to an application by email.
Clerk · Module
Creates an application invitation for an email address and sends the invitation email by default. It returns the newly created Invitation resource.
Call the Backend SDK method with the recipient's email and optional delivery and redirect settings. Clerk creates the invitation, sends its email by default, and returns the resulting Invitation resource.
function createInvitation(params: CreateParams): Promise<Invitation>| Name | Type | Description |
|---|---|---|
emailAddress | string | The email address of the user to invite. |
expiresInDays? | number | The number of days until the invitation expires; defaults to 30. |
ignoreExisting? | boolean | Whether to create an invitation when an invitation or user already exists; defaults to false. |
notify? | boolean | Whether an email invitation is sent; defaults to true. |
redirectUrl? | string | The full URL or path where the user lands after accepting the invitation. |
publicMetadata? | object | Additional metadata associated with the invitation. |
Promise<Invitation>
import { createClerkClient } from '@clerk/backend'
const clerkClient = createClerkClient({
secretKey: process.env.CLERK_SECRET_KEY,
})
const invitation = await clerkClient.invitations.createInvitation({
emailAddress: 'invite@example.com',
redirectUrl: 'https://www.example.com/my-sign-up',
publicMetadata: { source: 'admin' },
})
console.log(invitation.id)Creates and sends an application invitation, then logs the returned invitation identifier.
An administrator needs to add a person to an application by email.
A product needs invitation links to open a custom onboarding route.
An integration must attach structured context to an invitation.
It creates an application invitation for an email address, sends the invitation email, and resolves to the newly created Invitation. The method signature is createInvitation(params: CreateParams): Promise<Invitation>.
Follow-up: What happens for an already invited address? By default the call errors; setting ignoreExisting to true allows creation of another invitation.
emailAddress identifies the recipient and is required. expiresInDays controls the lifetime and defaults to 30, while notify controls email delivery and defaults to true.
Follow-up: How would you prevent an email from being sent? Pass notify: false while still creating the invitation.
The optional redirectUrl specifies the full URL or path where the user lands after accepting the invitation. The method is rate limited to 100 requests per hour per application instance.
Follow-up: How can multiple users be invited in one request? Use the separate createInvitationBulk() method.
createInvitationBulk()InvitationclerkClientCreateParams