|
| 1 | +--- |
| 2 | +title: '`createInvitationBulk()`' |
| 3 | +description: Use Clerk's JS Backend SDK to create multiple invitations for the given email addresses, and send the invitation emails. |
| 4 | +sdk: js-backend |
| 5 | +--- |
| 6 | + |
| 7 | +{/* clerk/javascript file: https://github.com/clerk/javascript/blob/main/packages/backend/src/api/endpoints/InvitationApi.ts#L69 */} |
| 8 | + |
| 9 | +Creates multiple [`Invitation`](/docs/reference/backend/types/backend-invitation)s in bulk for the given email addresses and sends the invitation emails. |
| 10 | + |
| 11 | +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`. |
| 12 | + |
| 13 | +```ts |
| 14 | +function createInvitationBulk(params: CreateBulkParams): Promise<Invitation[]> |
| 15 | +``` |
| 16 | + |
| 17 | +## Parameters |
| 18 | + |
| 19 | +<Properties> |
| 20 | + - `params` |
| 21 | + - [`CreateBulkParams[]`](#create-bulk-params) |
| 22 | + |
| 23 | + An array of objects, each representing a single invitation. |
| 24 | +</Properties> |
| 25 | + |
| 26 | +## `CreateBulkParams` |
| 27 | + |
| 28 | +<Properties> |
| 29 | + - `emailAddress` |
| 30 | + - `string` |
| 31 | + |
| 32 | + The email address of the user to invite. |
| 33 | + |
| 34 | + --- |
| 35 | + |
| 36 | + - `redirectUrl?` |
| 37 | + - `string` |
| 38 | + |
| 39 | + The full URL or path where the user is redirected upon visiting the invitation link, where they can accept the invitation. Required if you have implemented a [custom flow for handling application invitations](/docs/guides/development/custom-flows/authentication/application-invitations). |
| 40 | + |
| 41 | + --- |
| 42 | + |
| 43 | + - `publicMetadata?` |
| 44 | + - [`UserPublicMetadata`](/docs/reference/javascript/types/metadata#user-public-metadata) |
| 45 | + |
| 46 | + Metadata that can be read from both the Frontend API and [Backend API](/docs/reference/backend-api){{ target: '_blank' }}, 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. |
| 47 | + |
| 48 | + --- |
| 49 | + |
| 50 | + - `notify?` |
| 51 | + - `boolean` |
| 52 | + |
| 53 | + Whether an email invitation should be sent to the given email address. Defaults to `true`. |
| 54 | + |
| 55 | + --- |
| 56 | + |
| 57 | + - `ignoreExisting?` |
| 58 | + - `boolean` |
| 59 | + |
| 60 | + 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`. |
| 61 | + |
| 62 | + --- |
| 63 | + |
| 64 | + - `expiresInDays?` |
| 65 | + - `number` |
| 66 | + |
| 67 | + The number of days the invitation will be valid for. By default, the invitation expires after 30 days. |
| 68 | + |
| 69 | + --- |
| 70 | + |
| 71 | + - `templateSlug?` |
| 72 | + - `'invitation' | 'waitlist_invitation'` |
| 73 | + |
| 74 | + The slug of the email template to use for the invitation email. Defaults to `invitation`. |
| 75 | +</Properties> |
| 76 | + |
| 77 | +## Example |
| 78 | + |
| 79 | +<Include src="_partials/backend/usage" /> |
| 80 | + |
| 81 | +```tsx |
| 82 | +// Each object in the array represents a single invitation |
| 83 | +const params = [ |
| 84 | + { |
| 85 | + emailAddress: '[email protected]', |
| 86 | + redirectUrl: 'https://www.example.com/my-sign-up', |
| 87 | + publicMetadata: { |
| 88 | + example: 'metadata', |
| 89 | + example_nested: { |
| 90 | + nested: 'metadata', |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + { |
| 95 | + emailAddress: '[email protected]', |
| 96 | + redirectUrl: 'https://www.example.com/my-sign-up', |
| 97 | + publicMetadata: { |
| 98 | + example: 'metadata', |
| 99 | + example_nested: { |
| 100 | + nested: 'metadata', |
| 101 | + }, |
| 102 | + }, |
| 103 | + }, |
| 104 | +] |
| 105 | +
|
| 106 | +const response = await clerkClient.invitations.createInvitationBulk(params) |
| 107 | +``` |
| 108 | + |
| 109 | +## Backend API (BAPI) endpoint |
| 110 | + |
| 111 | +This method in the SDK is a wrapper around the BAPI endpoint `POST/invitations/bulk`. See the [BAPI reference](/docs/reference/backend-api/tag/invitations/post/invitations/bulk){{ target: '_blank' }} for more information. |
0 commit comments