0

Toggle the delivery by Clerk for a template of a given type and slug

by
Published Apr 8, 2025

Toggles the delivery by Clerk for a template of a given type and slug. If disabled, Clerk will not deliver the resulting email or SMS. The app developer will need to listen to the `email.created` or `sms.created` webhooks in order to handle delivery themselves.

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Toggle the delivery by Clerk for a template of a given type and slug
7
 * Toggles the delivery by Clerk for a template of a given type and slug.
8
If disabled, Clerk will not deliver the resulting email or SMS.
9
The app developer will need to listen to the `email.created` or `sms.created` webhooks in order to handle delivery themselves.
10
 */
11
export async function main(
12
  auth: Clerk,
13
  template_type: "email" | "sms",
14
  slug: string,
15
  body: { delivered_by_clerk?: false | true },
16
) {
17
  const url = new URL(
18
    `https://api.clerk.com/v1/templates/${template_type}/${slug}/toggle_delivery`,
19
  );
20

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