Edits history of script submission #12051 for ' Toggle the delivery by Clerk for a template of a given type and slug (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Toggle the delivery by Clerk for a template of a given type and slug
     * 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.
     */
    export async function main(
      auth: Clerk,
      template_type: "email" | "sms",
      slug: string,
      body: { delivered_by_clerk?: false | true },
    ) {
      const url = new URL(
        `https://api.clerk.com/v1/templates/${template_type}/${slug}/toggle_delivery`,
      );
    
      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