//native
type Clerk = {
apiKey: string;
};
/**
* Create an invitation
* Creates a new invitation for the given email address and sends the invitation email.
Keep in mind that you cannot create an invitation if there is already one for the given email address.
Also, trying to create an invitation for an email address that already exists in your application will result to an error.
*/
export async function main(
auth: Clerk,
body: {
email_address: string;
public_metadata?: {};
redirect_url?: string;
notify?: false | true;
ignore_existing?: false | true;
expires_in_days?: number;
template_slug?: "invitation" | "waitlist_invitation";
},
) {
const url = new URL(`https://api.clerk.com/v1/invitations`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago