0

Create multiple invitations

by
Published Apr 8, 2025

Use this API operation to create multiple invitations for the provided email addresses. You can choose to send the invitations as emails by setting the `notify` parameter to `true`. There cannot be an existing invitation for any of the email addresses you provide unless you set `ignore_existing` to `true` for specific email addresses. Please note that there must be no existing user for any of the email addresses you provide, and this rule cannot be bypassed.

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Create multiple invitations
7
 * Use this API operation to create multiple invitations for the provided email addresses. You can choose to send the
8
invitations as emails by setting the `notify` parameter to `true`. There cannot be an existing invitation for any
9
of the email addresses you provide unless you set `ignore_existing` to `true` for specific email addresses. Please
10
note that there must be no existing user for any of the email addresses you provide, and this rule cannot be bypassed.
11
 */
12
export async function main(
13
  auth: Clerk,
14
  body: {
15
    email_address: string;
16
    public_metadata?: {};
17
    redirect_url?: string;
18
    notify?: false | true;
19
    ignore_existing?: false | true;
20
    expires_in_days?: number;
21
  }[],
22
) {
23
  const url = new URL(`https://api.clerk.com/v1/invitations/bulk`);
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.apiKey,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39