Edits history of script submission #18029 for ' Delete a password (planetscale)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Planetscale = {
      serviceTokenId: string;
      serviceToken: string;
    };
    /**
     * Delete a password
     * 
    ### Authorization
    A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint:
    
    **Service Token Accesses**
     `delete_production_branch_password`, `delete_branch_password`
    
    **OAuth Scopes**
    
     | Resource | Scopes |
    | :------- | :---------- |
    | Organization | `manage_passwords`, `manage_production_branch_passwords` |
    | Database | `manage_passwords`, `manage_production_branch_passwords` |
    | Branch | `manage_passwords` |
     */
    export async function main(
      auth: Planetscale,
      organization: string,
      database: string,
      branch: string,
      id: string,
    ) {
      const url = new URL(
        `https://api.planetscale.com/v1/organizations/${organization}/databases/${database}/branches/${branch}/passwords/${id}`,
      );
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago