Edits history of script submission #14923 for ' Search for a user by ID (cockroachdb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cockroachdb = {
      token: string;
    };
    /**
     * Search for a user by ID
     * Similar to GetUser however search parameters are passed via the POST body. See https://www.rfc-editor.org/rfc/rfc7644.html#section-3.4.3 for more details.
    
    Can be used by the following roles assigned at the organization scope:
    - ORG_ADMIN
    
     */
    export async function main(
      auth: Cockroachdb,
      id: string,
      body: { attributes?: string; excludedAttributes?: string },
    ) {
      const url = new URL(
        `https://cockroachlabs.cloud/api/scim/v2/Users/${id}/.search`,
      );
    
      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