Edits history of script submission #11869 for ' Create Bulk Action (buttondown)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Buttondown = {
      token: string;
    };
    /**
     * Create Bulk Action
     *
     */
    export async function main(
      auth: Buttondown,
      body: {
        type:
          | "apply_tags"
          | "apply_metadata"
          | "ban_subscribers"
          | "delete_subscribers"
          | "gift_subscribers"
          | "reactivate_subscribers"
          | "mark_subscribers_as_not_spammy"
          | "resubscribe_subscribers"
          | "send_emails"
          | "unsubscribe_subscribers"
          | "send_reminders"
          | "delete_emails"
          | "update_email_types"
          | "delete_tags"
          | "delete_surveys"
          | "replay_events"
          | "delete_comments"
          | "update_survey_statuses";
        metadata: {};
      },
    ) {
      const url = new URL(`https://api.buttondown.com/v1/bulk_actions`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Token " + auth.token,
        },
        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