Docs

getOrganizationMembershipList()

Retrieves a list of organization memberships for a given user.

function getOrganizationMembershipList: (params: GetOrganizationMembershipListParams) => Promise<PaginatedResourceResponse<OrganizationMembership[]>>;
  • Name
    userId
    Type
    string
    Description

    The ID of the user to retrieve the list of organization memberships for.

  • Name
    limit?
    Type
    number
    Description

    The number of results to return. Must be an integer greater than zero and less than 501.

  • Name
    offset?
    Type
    number
    Description

    The number of results to skip.

getOrganizationMembershipList() examples

getOrganizationMembershipList({ userId })

In this example, you can see that the returned PaginatedResourceResponse includes data, which is an array of OrganizationMembership objects, and totalCount, which indicates the total number of organization memberships in the system for the specified organization.

const userId = 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56';

const response = await clerkClient.users.getOrganizationMembershipList({ userId });

console.log(response);
/*
{
  data: [
    _OrganizationMembership {
      id: 'orgmem_2bjJ8KfbbOyzmF4wMRU7kjHvsgI',
      role: 'org:admin',
      publicMetadata: {},
      privateMetadata: {},
      createdAt: 1706722393158,
      updatedAt: 1706722393158,
      organization: [_Organization],
      publicUserData: [_OrganizationMembershipPublicUserData]
    },
    _OrganizationMembership {
      id: 'orgmem_2bjJ4JMtzPQIBRWQqeFKdJ0fg1s',
      role: 'org:admin',
      publicMetadata: {},
      privateMetadata: {},
      createdAt: 1706722361154,
      updatedAt: 1706722361154,
      organization: [_Organization],
      publicUserData: [_OrganizationMembershipPublicUserData]
    }
  ],
  totalCount: 2
}
*/

getOrganizationMembershipList({ userId, limit })

Retrieves a list of a user's organization memberships that is filtered by the number of results.

const userId = 'user_123';

const { data, totalCount } = await clerkClient.users.getOrganizationMembershipList({
  userId,
  // returns the first 10 memberships
  limit: 10,
});

getOrganizationMembershipList({ userId, offset })

Retrieves a list of a user's organization memberships that is filtered by the number of results to skip.

const userId = 'user_123';

const { data, totalCount } = await clerkClient.users.getOrganizationMembershipList({
  userId,
  // skips the first 10 memberships
  offset: 10,
});

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint GET/users/{user_id}/organization_memberships. See the BAPI reference for more details.

Feedback

What did you think of this content?