Edits history of script submission #14829 for ' Create a new API Key (cockroachdb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cockroachdb = {
      token: string;
    };
    /**
     * Create a new API Key
     * Can be used by the following roles assigned at the organization scope:
    - ORG_ADMIN
    
     */
    export async function main(
      auth: Cockroachdb,
      body: { name: string; service_account_id: string },
    ) {
      const url = new URL(`https://cockroachlabs.cloud/api/v1/api-keys`);
    
      const response = await fetch(url, {
        method: "POST",
        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