Skip to Content
You are viewing a beta version of Clerk Docs
Visit the latest docs
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

updateOrganizationMembership()

Updates a user's organization membership. Currently, only the role can be updated.

function updateOrganizationMembership: (params: UpdateOrganizationMembershipParams) => Promise<OrganizationMembership>;

UpdateOrganizationMembershipParams

NameTypeDescription
organizationIdstringThe organization ID of the organization a user belongs to.
userIdstringThe ID of the user.
rolestringThe role to assign user.

updateOrganizationMembership() example

In this example, you can see that the returned OrganizationMembership object has its role property updated to org:admin.

const organizationId = 'org_2ZUtbk2yvnFGItdeze1ivCh3uqh'; const userId = 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56'; const role = 'org:admin'; const response = await clerkClient.organizations.updateOrganizationMembership({organizationId, userId, role}); console.log(response); /* _OrganizationMembership { id: 'orgmem_2ZUtbeklm2DPSy7jsaLLwf6V8Nq', role: 'org:admin', publicMetadata: {}, privateMetadata: {}, createdAt: 1702488558867, updatedAt: 1705535333002, organization: _Organization { id: 'org_2ZUtbk2yvnFGItdeze1ivCh3uqh', name: 'Test', slug: 'test', imageUrl: 'https://img.clerk.com/eyJ0eXBlIjoiZGVmYXVsdCIsImlpZCI6Imluc18yVjdKRFdyclJwRmZFZTlqQUM2dWpSMG8xSlQiLCJyaWQiOiJvcmdfMlpVdGJrMnl2bkZHSXRkZXplMWl2Q2gzdXFoIiwiaW5pdGlhbHMiOiJUIn0', hasImage: false, createdBy: 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56', createdAt: 1702488558853, updatedAt: 1705534260298, publicMetadata: {}, privateMetadata: {}, maxAllowedMemberships: 3, adminDeleteEnabled: true, members_count: undefined }, publicUserData: _OrganizationMembershipPublicUserData { identifier: 'alexis@clerk.dev', firstName: 'Alexis', lastName: 'Aguilar', imageUrl: 'https://img.clerk.com/eyJ0eXBlIjoicHJveHkiLCJzcmMiOiJodHRwczovL2ltYWdlcy5jbGVyay5kZXYvb2F1dGhfZ29vZ2xlL2ltZ18yVjdKSkhvdXlnbDNLRXRaUjlRRlFNbnVDU2cuanBlZyJ9', hasImage: true, userId: 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56' } } */

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint PATCH/organizations/{organization_id}/memberships/{user_id}. See the BAPI reference(opens in a new tab) for more details.

Last updated on December 19, 2023

What did you think of this content?

Clerk © 2024