Edits history of script submission #17148 for ' Update a NodeBalancer (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Update a NodeBalancer
     * Updates information about a NodeBalancer you can access.
    
    
    >
    
    ---
    
    
    - __CLI__.
    
        ```
        linode-cli nodebalancers update 12345 \
      --label balancer12345 \
      --client_conn_throttle 0
        ```
    
        [Learn more...](https://techdocs.akamai.com/cloud-computing/docs/getting-started-with-the-linode-cli)
    
    - __OAuth scopes__.
    
        ```
        nodebalancers:read_write
        ```
    
        [Learn more...](https://techdocs.akamai.com/linode-api/reference/get-started#oauth)
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      nodeBalancerId: string,
      body: {
        client_conn_throttle?: number;
        created?: string;
        hostname?: string;
        id?: number;
        ipv4?: string;
        ipv6?: string;
        label?: string;
        lke_cluster?: { id?: string; label?: string; type?: string; url?: string };
        region?: string;
        tags?: string[];
        transfer?: { in?: number; out?: number; total?: number };
        type?: "common";
        updated?: string;
      },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + 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 235 days ago