Edits history of script submission #14914 for ' Patch a group by supplying partial updates (cockroachdb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cockroachdb = {
      token: string;
    };
    /**
     * Patch a group by supplying partial updates
     * Apply a sequence of operations to modify attributes of a SCIM Group resource. Supports 'add', 'remove', and 'replace' operations per RFC 7644 Section 3.5.2. Operations are applied atomically — if any operation fails, no changes are applied. The request body must include the 'schemas' field set to 'urn:ietf:params:scim:api:messages:2.0:PatchOp'.
    
    Can be used by the following roles assigned at the organization scope:
    - ORG_ADMIN
    
     */
    export async function main(
      auth: Cockroachdb,
      id: string,
      body: {
        Operations: { op: string; path?: string; value?: unknown }[];
        schemas: string[];
      },
    ) {
      const url = new URL(`https://cockroachlabs.cloud/api/scim/v2/Groups/${id}`);
    
      const response = await fetch(url, {
        method: "PATCH",
        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