|
| 1 | +--- |
| 2 | +title: '`createOrganizationInvitationBulk()`' |
| 3 | +description: Use Clerk's Backend SDK to create multiple invitations for new users to join an organization. |
| 4 | +--- |
| 5 | + |
| 6 | +{/* clerk/javascript file: https://github.com/clerk/javascript/blob/main/packages/backend/src/api/endpoints/OrganizationApi.ts#L292-L303 */} |
| 7 | + |
| 8 | +Creates multiple [`OrganizationInvitation`](/docs/references/backend/types/backend-organization-invitation)s in bulk for new users to join an organization. |
| 9 | + |
| 10 | +```ts |
| 11 | +function createOrganizationInvitationBulk( |
| 12 | + organizationId: string, |
| 13 | + params: CreateBulkOrganizationInvitationParams, |
| 14 | +): Promise<OrganizationInvitation> |
| 15 | +``` |
| 16 | + |
| 17 | +## `CreateBulkOrganizationInvitationParams` |
| 18 | + |
| 19 | +<Properties> |
| 20 | + - `inviterUserId` |
| 21 | + - `string | null` |
| 22 | + |
| 23 | + The user ID of the user creating the invitation. |
| 24 | + |
| 25 | + --- |
| 26 | + |
| 27 | + - `emailAddress` |
| 28 | + - `string` |
| 29 | + |
| 30 | + The email address to send the invitation to. |
| 31 | + |
| 32 | + --- |
| 33 | + |
| 34 | + - `role` |
| 35 | + - `string` |
| 36 | + |
| 37 | + The [role](/docs/organizations/roles-permissions) to assign the invited user within the organization. |
| 38 | + |
| 39 | + --- |
| 40 | + |
| 41 | + - `redirectUrl?` |
| 42 | + - `string` |
| 43 | + |
| 44 | + The full URL or path where users will land once the organization invitation has been accepted. |
| 45 | + |
| 46 | + --- |
| 47 | + |
| 48 | + - `publicMetadata?` |
| 49 | + - [`OrganizationInvitationPublicMetadata`](/docs/references/javascript/types/metadata#organization-invitation-public-metadata) |
| 50 | + |
| 51 | + 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. |
| 52 | +</Properties> |
| 53 | + |
| 54 | +## Example |
| 55 | + |
| 56 | +<Include src="_partials/backend/usage" /> |
| 57 | + |
| 58 | +```tsx |
| 59 | +const organizationId = 'org_123' |
| 60 | +const params = [ |
| 61 | + { |
| 62 | + inviterUserId: 'user_1', |
| 63 | + emailAddress: 'testclerk1@clerk.dev', |
| 64 | + role: 'org:admin' |
| 65 | + }, |
| 66 | + { |
| 67 | + inviterUserId: 'user_2', |
| 68 | + emailAddress: 'testclerk2@clerk.dev', |
| 69 | + role: 'org:member' |
| 70 | + } |
| 71 | +] |
| 72 | +
|
| 73 | +const response = await clerkClient.organizations.createOrganizationInvitationBulk(organizationId, params) |
| 74 | +``` |
| 75 | + |
| 76 | +## Backend API (BAPI) endpoint |
| 77 | + |
| 78 | +This method in the SDK is a wrapper around the BAPI endpoint `POST/organizations/{organization_id}/invitations/bulk`. See the [BAPI reference](/docs/reference/backend-api/tag/Organization-Invitations#operation/CreateOrganizationInvitationBulk){{ target: '_blank' }} for more information. |
0 commit comments