Docs

updateOrganizationMembership()

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

function updateOrganizationMembership: (params: UpdateOrganizationMembershipParams) => Promise<OrganizationMembership>;
  • Name
    organizationId
    Type
    string
    Description

    The organization ID of the organization a user belongs to.

  • Name
    userId
    Type
    string
    Description

    The ID of the user.

  • Name
    role
    Type
    string
    Description

    The role to assign user.

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 for more details.

Feedback

What did you think of this content?