Edits history of script submission #11871 for ' Create Export (buttondown)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Buttondown = {
      token: string;
    };
    /**
     * Create Export
     *
     */
    export async function main(
      auth: Buttondown,
      body: {
        collections:
          | "subscribers"
          | "emails"
          | "events"
          | "referrals"
          | "surveys"
          | "comments"
          | "requests"
          | "mentions"
          | "conversations"[];
        parameters?: {};
        columns?: string[];
      },
    ) {
      const url = new URL(`https://api.buttondown.com/v1/exports`);
    
      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