Edits history of script submission #18076 for ' Update an organization (planetscale)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Planetscale = {
      serviceTokenId: string;
      serviceToken: string;
    };
    /**
     * Update an organization
     * 
    ### Authorization
    A   OAuth token must have at least one of the following   scopes in order to use this API endpoint:
    
    **OAuth Scopes**
    
     | Resource | Scopes |
    | :------- | :---------- |
    | Organization | `write_organization` |
     */
    export async function main(
      auth: Planetscale,
      name: string,
      body: {
        billing_email?: string;
        idp_managed_roles?: false | true;
        invoice_budget_amount?: number;
      },
    ) {
      const url = new URL(`https://api.planetscale.com/v1/organizations/${name}`);
    
      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.json();
    }
    

    Submitted by hugo697 235 days ago