0

Update a template for a given type and slug

by
Published Apr 8, 2025

Updates the existing template of the given type and slug

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Update a template for a given type and slug
7
 * Updates the existing template of the given type and slug
8
 */
9
export async function main(
10
  auth: Clerk,
11
  template_type: "email" | "sms",
12
  slug: string,
13
  body: {
14
    name?: string;
15
    subject?: string;
16
    markup?: string;
17
    body?: string;
18
    delivered_by_clerk?: false | true;
19
    from_email_name?: string;
20
    reply_to_email_name?: string;
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.clerk.com/v1/templates/${template_type}/${slug}`,
25
  );
26

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