Endpoint
Authentication
This endpoint requires authentication. User must be logged in with a valid session.Request Body
The role to assign to the invited user.
The email address of the user to send an invitation email to. When provided, creates a private invite. When omitted, creates a public invite link.
Type of token to use:
"token": 24-character token"code": 6-digit code"custom": Usesoptions.generateToken
options.defaultTokenTypeThe URL to redirect the user to create their account. If the token is invalid or expired, redirects with
?error=INVALID_TOKEN. If valid, redirects with ?token=VALID_TOKEN.Default: options.defaultRedirectToSignUpThe URL to redirect the user to upgrade their role.Default:
options.defaultRedirectToSignInThe number of times an invitation can be used.Default:
options.defaultMaxUses (1 for private invites, infinite for public invites)Number of seconds the invitation token is valid for.Default:
options.invitationTokenExpiresIn (3600 seconds / 1 hour)The URL to redirect the user to after upgrading their role (if the user is already logged in).
{token} will be replaced with the user’s actual token.Default: options.defaultRedirectAfterUpgradeWhether the inviter’s name should be shared with the invitee. When enabled, the person receiving the invitation will see the name of the user who created the invitation.Default:
options.defaultShareInviterName (true)How should the sender receive the token. Only applies when no email is provided (public invites).
"token": Returns just the token string"url": Returns the complete activation URL
options.defaultSenderResponse (“token”)Where should the invite redirect the user? Only applies when no email is provided (public invites).Default:
options.defaultSenderResponseRedirect (“signUp”)Custom URL pattern for the invitation. Use
{token} and {callbackUrl} placeholders, which will be replaced with their actual values.Response
Success Response (200)
Always
true on success.For private invites (with email):
"The invitation was sent"For public invites (no email): Contains the token or URL based on senderResponse setting.Examples
Private Invite (with Email)
Request:[email protected] will receive an email via the sendUserInvitation function configured in plugin options.
Public Invite (Shareable Link)
Request:message field contains the shareable invitation URL.
Invite with Custom Settings
Request:Error Responses
Insufficient Permissions (400)
- User doesn’t have permission based on
canCreateInviteoption - User doesn’t meet custom permission requirements
Invitation Email Not Enabled (500)
- Creating a private invite without configuring
sendUserInvitationin plugin options
Email Sending Failed (500)
- The
sendUserInvitationfunction throws an error
Behavior
Private Invites (with email)
- Checks if the email belongs to an existing user
- Determines if this is a new account invitation or role upgrade
- Creates invitation record in database
- Sends email via
sendUserInvitationfunction - Returns success confirmation
Public Invites (without email)
- Creates invitation record with no email restriction
- Returns token or URL based on
senderResponsesetting - Token/URL can be shared and used by anyone (up to
maxUsestimes)
Hooks
The following hooks are triggered during this endpoint:beforeCreateInvite: Called before creating the invitationafterCreateInvite: Called after the invitation is created successfully
Permissions
Permission is checked using thecanCreateInvite option:
Source Code Reference
Implementation:src/routes/create-invite.ts:13-193
Body schema: src/body.ts:4-122
Related
- Activate Invite - Activate an invitation token
- Get Invite - Get invitation details
- Cancel Invite - Cancel a pending invitation
- InviteOptions - Plugin configuration options