Docs

createInvitation()

Creates a new Invitation for the given email address and sends the invitation email.

If an email address has already been invited or already exists in your application, trying to create a new invitation will return an error. To bypass this error and create a new invitation anyways, set ignoreExisting to true.

function createInvitation(params: CreateParams): Promise<Invitation>
  • Name
    emailAddress
    Type
    string
    Description

    The email address of the user to invite.

  • Name
    redirectUrl?
    Type
    string
    Description

    The URL to redirect the user to when they visit the invitation link.

  • Name
    publicMetadata?
    Type
    {[string]: any}
    Description

    Metadata that can be read from both the Frontend API and Backend API, but can be set only from the Backend API. Once the user accepts the invitation and signs up, these metadata will end up in the user's public metadata.

  • Name
    notify?
    Type
    boolean
    Description

    Whether an email invitation should be sent to the given email address. Defaults to true.

  • Name
    ignoreExisting?
    Type
    boolean
    Description

    Whether an invitation should be created if there is already an existing invitation for this email address, or if the email address already exists in the application. Defaults to false.

const response = await clerkClient.invitations.createInvitation({
  emailAddress: 'invite@example.com',
  redirectUrl: 'https://www.example.com/my-sign-up',
  publicMetadata: {
    example: 'metadata',
    example_nested: {
      nested: 'metadata',
    },
  },
})

console.log(response)
/*
_Invitation {
  id: 'inv_123',
  emailAddress: 'invite@example.com',
  publicMetadata: { example: 'metadata', example_nested: [Object] },
  createdAt: 1705531674576,
  updatedAt: 1705531674576,
  status: 'pending',
  revoked: undefined
}
*/

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint POST/invitations. See the BAPI reference for more details.

Feedback

What did you think of this content?

Last updated on