Edits history of script submission #11904 for ' List Emails (buttondown)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Buttondown = {
      token: string;
    };
    /**
     * List Emails
     *
     */
    export async function main(
      auth: Buttondown,
      status: string | undefined,
      automations: string | undefined,
      ids: string | undefined,
      ordering: string | undefined,
      creation_date__start: string | undefined,
      creation_date__end: string | undefined,
      publish_date__start: string | undefined,
      publish_date__end: string | undefined,
      excluded_fields: string | undefined,
      source: string | undefined,
      email_type: string | undefined,
    ) {
      const url = new URL(`https://api.buttondown.com/v1/emails`);
      for (const [k, v] of [
        ["status", status],
        ["automations", automations],
        ["ids", ids],
        ["ordering", ordering],
        ["creation_date__start", creation_date__start],
        ["creation_date__end", creation_date__end],
        ["publish_date__start", publish_date__start],
        ["publish_date__end", publish_date__end],
        ["excluded_fields", excluded_fields],
        ["source", source],
        ["email_type", email_type],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Token " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago