Edits history of script submission #12024 for ' Preview changes to a template (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Preview changes to a template
     * Returns a preview of a template for a given template_type, slug and body
     */
    export async function main(
      auth: Clerk,
      template_type: string,
      slug: string,
      body: {
        subject?: string;
        body?: string;
        from_email_name?: string;
        reply_to_email_name?: string;
      },
    ) {
      const url = new URL(
        `https://api.clerk.com/v1/templates/${template_type}/${slug}/preview`,
      );
    
      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