//native
type Clerk = {
apiKey: string;
};
/**
* Update a template for a given type and slug
* Updates the existing template of the given type and slug
*/
export async function main(
auth: Clerk,
template_type: "email" | "sms",
slug: string,
body: {
name?: string;
subject?: string;
markup?: string;
body?: string;
delivered_by_clerk?: false | true;
from_email_name?: string;
reply_to_email_name?: string;
},
) {
const url = new URL(
`https://api.clerk.com/v1/templates/${template_type}/${slug}`,
);
const response = await fetch(url, {
method: "PUT",
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