Edits history of script submission #18015 for ' Change a branch cluster configuration (planetscale)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Planetscale = {
      serviceTokenId: string;
      serviceToken: string;
    };
    /**
     * Change a branch cluster configuration
     * 
    ### Authorization
    A service token   must have at least one of the following access   in order to use this API endpoint:
    
    **Service Token Accesses**
     `write_database`
    
    
     */
    export async function main(
      auth: Planetscale,
      organization: string,
      database: string,
      name: string,
      body: { cluster_size: string },
    ) {
      const url = new URL(
        `https://api.planetscale.com/v1/organizations/${organization}/databases/${database}/branches/${name}/cluster`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago