Edits history of script submission #10862 for ' List All Apps (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * List All Apps
     * List all apps on your account. Information about the current active deployment as well as any in progress ones will also be included for each app.
     */
    export async function main(
      auth: Digitalocean,
      page: string | undefined,
      per_page: string | undefined,
      with_projects: string | undefined,
    ) {
      const url = new URL(`https://api.digitalocean.com/v2/apps`);
      for (const [k, v] of [
        ["page", page],
        ["per_page", per_page],
        ["with_projects", with_projects],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + 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 536 days ago