Skip to Content

Users and groups

Look up users, search and list them, read group memberships, manage group members, and read markings with @osdk/foundry.admin.

Foundry docsUser APIGroup API

@osdk/foundry.admin reads and manages Foundry users, groups, and markings. Use it to show who is signed in, resolve user IDs to names, check group membership, and list the markings a user can view.

npm install @osdk/client @osdk/oauth @osdk/foundry.admin

Every sample takes a client from createClient or createPlatformClient; see Set up. Reads need the api:admin-read scope and writes need api:admin-write. In React, the hooks in @osdk/react/platform-apis wrap several of these calls; see Users and markings in React.

Get the signed-in user

Users.getCurrent returns the user the token belongs to:

src/currentUser.ts
import type { Client } from "@osdk/client";
import { Users } from "@osdk/foundry.admin";

export async function displayName(client: Client): Promise<string> {
  const user = await Users.getCurrent(client);
  const fullName = [user.givenName, user.familyName].filter(Boolean).join(" ");
  return fullName || user.username;
}

A User has these fields:

FieldTypeDescription
idstringThe user ID. Other endpoints take this as userId or principalId.
usernamestringThe username.
givenNamestring | undefinedFirst name.
familyNamestring | undefinedLast name.
emailstring | undefinedEmail address.
realmstringThe authentication realm the user belongs to.
organizationstring | undefinedRID of the user's primary organization.
status"ACTIVE" | "DELETED"Whether the user is active.
attributesRecord<string, string[]>Attributes from the identity provider.

Look up users by ID

Users.get takes a user ID. Pass status: "DELETED" to resolve a user who has been removed, for example the author of an old record:

src/lookupUser.ts
import type { Client } from "@osdk/client";
import { Users } from "@osdk/foundry.admin";

export async function lookupUser(client: Client, userId: string) {
  const active = await Users.get(client, userId);
  const deleted = await Users.get(client, userId, { status: "DELETED" });
  return { active, deleted };
}

To resolve many IDs at once, use Users.getBatch. It takes up to 500 elements and returns a map keyed by user ID. IDs that do not resolve are missing from the map:

src/resolveUsers.ts
import type { Client } from "@osdk/client";
import { Users, type User } from "@osdk/foundry.admin";

export async function resolveUsers(
  client: Client,
  userIds: string[],
): Promise<Map<string, User>> {
  const { data } = await Users.getBatch(
    client,
    userIds.map((userId) => ({ userId })),
  );
  return new Map(Object.entries(data));
}

Search and list users

Users.search runs a case-insensitive prefix search on username, given name, and family name. It only returns active users:

src/searchUsers.ts
import type { Client } from "@osdk/client";
import { Users } from "@osdk/foundry.admin";

export async function searchUsers(client: Client, prefix: string) {
  const { data, nextPageToken } = await Users.search(client, {
    where: { type: "queryString", value: prefix },
    pageSize: 20,
  });
  return { users: data, nextPageToken };
}

Users.list lists every user, one page at a time. Its query parameters:

OptionTypeDefaultDescription
include"ACTIVE" | "DELETED"Active usersWhich users to list. Pass "DELETED" to list removed users.
pageSizenumberPreferred page size. The server can return more or fewer.
pageTokenstringnextPageToken from the previous page.

To read every page, use the paginate helper from Call platform APIs.

Show a profile picture

Users.profilePicture returns the image as a Response:

src/profilePicture.ts
import type { Client } from "@osdk/client";
import { Users } from "@osdk/foundry.admin";

export async function profilePictureUrl(client: Client, userId: string): Promise<string> {
  const response = await Users.profilePicture(client, userId);
  return URL.createObjectURL(await response.blob());
}

A user without a picture rejects with a ProfilePictureNotFound error.

Read group memberships

Groups.listCurrent returns every group the signed-in user belongs to, directly or through another group. It needs no scope, so any signed-in user can call it, but it is a preview endpoint:

src/myGroups.ts
import type { Client } from "@osdk/client";
import { Groups } from "@osdk/foundry.admin";

export async function isInGroup(client: Client, groupName: string): Promise<boolean> {
  const { data } = await Groups.listCurrent(client, { preview: true });
  return data.some((group) => group.name === groupName);
}

For any other user, GroupMemberships.list returns the IDs of their groups. Set transitive: true to include groups they belong to through other groups, then resolve the IDs with Groups.getBatch:

src/userGroups.ts
import type { Client } from "@osdk/client";
import { GroupMemberships, Groups } from "@osdk/foundry.admin";

export async function userGroupNames(client: Client, userId: string): Promise<string[]> {
  const memberships = await GroupMemberships.list(client, userId, { transitive: true });
  const { data } = await Groups.getBatch(
    client,
    memberships.data.map(({ groupId }) => ({ groupId })),
  );
  return Object.values(data).map((group) => group.name);
}

This reads one page. Paginate with pageToken for users in many groups.

A Group has id, name, description, realm, organizations (organization RIDs), and attributes.

Find groups and their members

Groups.search runs a prefix search on group name. GroupMembers.list returns a group's members, which can be users or groups:

src/groupMembers.ts
import type { Client } from "@osdk/client";
import { GroupMembers, Groups, Users } from "@osdk/foundry.admin";

export async function memberUsernames(client: Client, groupName: string): Promise<string[]> {
  const { data: groups } = await Groups.search(client, {
    where: { type: "queryString", value: groupName },
  });
  const group = groups.find((g) => g.name === groupName);
  if (group == null) {
    return [];
  }

  const members = await GroupMembers.list(client, group.id, { transitive: true });
  const userIds = members.data
    .filter((member) => member.principalType === "USER")
    .map((member) => ({ userId: member.principalId }));
  const { data: users } = await Users.getBatch(client, userIds);
  return Object.values(users).map((user) => user.username);
}
OptionTypeDescription
transitivebooleanInclude members of nested groups.
includeExpirationsbooleanInclude each member's expiration, when one is set.
pageSize, pageTokenPagination. See Paginate.

Each member is { principalType: "USER" | "GROUP", principalId, expiration? }.

Add and remove group members

Adding and removing members needs api:admin-write and permission to manage the group. Both take the group ID and a list of principal IDs, which can be user or group IDs, and resolve to undefined:

src/manageMembers.ts
import type { Client } from "@osdk/client";
import { GroupMembers } from "@osdk/foundry.admin";

export async function addTemporaryMember(client: Client, groupId: string, userId: string) {
  await GroupMembers.add(client, groupId, {
    principalIds: [userId],
    expiration: "2026-12-31T23:59:59Z",
  });
}

export async function removeMember(client: Client, groupId: string, userId: string) {
  await GroupMembers.remove(client, groupId, { principalIds: [userId] });
}

expiration is optional. Without it, the membership does not expire.

Read markings

Markings restrict who can view a resource. Users.getMarkings returns the IDs of the markings a user is a member of, and Markings.list and MarkingCategories.list return the markings and categories the token can see. Join them on categoryId:

src/userMarkings.ts
import type { Client } from "@osdk/client";
import { MarkingCategories, Markings, Users } from "@osdk/foundry.admin";

export async function describeUserMarkings(client: Client, userId: string): Promise<string[]> {
  const [{ view }, markings, categories] = await Promise.all([
    Users.getMarkings(client, userId),
    Markings.list(client, { includeDeleted: false, pageSize: 100 }),
    MarkingCategories.list(client, { includeDeleted: false, pageSize: 100 }),
  ]);

  const categoryName = new Map(categories.data.map((c) => [c.id, c.name] as const));
  const viewable = new Set(view);
  return markings.data
    .filter((marking) => viewable.has(marking.id))
    .map((marking) => `${categoryName.get(marking.categoryId) ?? "Uncategorized"}: ${marking.name}`);
}

Markings.list and MarkingCategories.list accept at most 100 per page and include deleted entries unless you pass includeDeleted: false. Paginate to read them all. To look up specific markings, use Markings.get or Markings.getBatch.

Marking fieldDescription
idThe marking ID.
categoryIdThe category it belongs to.
name, descriptionDisplay text.
organizationThe organization RID, for organization markings.
deletedWhether the marking has been deleted.
createdTime, createdByWhen and by whom it was created.

Listing who can view a marking, with MarkingMembers.list, needs api:admin-write because only marking administrators can see its members.

For classification-based access control (CBAC), CbacBanners.get(client, { markingIds }) returns the banner text and colors for a set of marking IDs.

Reference

FunctionEndpointScopeStatus
Users.getCurrent(client)GET /v2/admin/users/getCurrentapi:admin-readStable
Users.get(client, userId, { status? })GET /v2/admin/users/{userId}api:admin-readStable
Users.getBatch(client, elements)POST /v2/admin/users/getBatchapi:admin-readStable
Users.list(client, { include?, pageSize?, pageToken? })GET /v2/admin/usersapi:admin-readStable
Users.search(client, body)POST /v2/admin/users/searchapi:admin-readStable
Users.profilePicture(client, userId)GET /v2/admin/users/{userId}/profilePictureapi:admin-readStable
Users.getMarkings(client, userId)GET /v2/admin/users/{userId}/getMarkingsapi:admin-readStable
Groups.listCurrent(client, { preview })GET /v2/admin/groups/listCurrentNoneBeta
Groups.get(client, groupId)GET /v2/admin/groups/{groupId}api:admin-readStable
Groups.getBatch(client, elements)POST /v2/admin/groups/getBatchapi:admin-readStable
Groups.search(client, body)POST /v2/admin/groups/searchapi:admin-readStable
GroupMemberships.list(client, userId, query?)GET /v2/admin/users/{userId}/groupMembershipsapi:admin-readStable
GroupMembers.list(client, groupId, query?)GET /v2/admin/groups/{groupId}/groupMembersapi:admin-readStable
GroupMembers.add(client, groupId, body)POST /v2/admin/groups/{groupId}/groupMembers/addapi:admin-writeStable
GroupMembers.remove(client, groupId, body)POST /v2/admin/groups/{groupId}/groupMembers/removeapi:admin-writeStable
Markings.list(client, query?)GET /v2/admin/markingsapi:admin-readStable
MarkingCategories.list(client, query?)GET /v2/admin/markingCategoriesapi:admin-readStable
MarkingMembers.list(client, markingId, query?)GET /v2/admin/markings/{markingId}/markingMembersapi:admin-writeStable
CbacBanners.get(client, { markingIds, displayType? })GET /v2/admin/cbacBannerapi:admin-readStable

The package also covers creating and deleting groups, deleting users, organizations, roles, enrollments, and authentication providers. Browse the exports of @osdk/foundry.admin in your editor for the full list.

On this page