Docs

updateOrganizationMembershipMetadata()

Update the metadata attributes of an OrganizationMembership by merging existing values with the provided parameters. Metadata values will be updated via a "deep" merge - "deep" means that any nested JSON objects will be merged as well. You can remove metadata keys at any level by setting their value to null.

function updateOrganizationMembershipMetadata(
  params: UpdateOrganizationMembershipMetadataParams,
): Promise<OrganizationMembership>

Example

In the following example, you can see that the returned OrganizationMembership object has its publicMetadata property updated with the new metadata provided.

const organizationId = 'org_123'

const userId = 'user_123'

const response = await clerkClient.organizations.updateOrganizationMembershipMetadata({
  organizationId,
  userId,
  publicMetadata: {
    example: 'this value is updated!',
  },
})

console.log(response)
/*
_OrganizationMembership {
  id: 'orgmem_213',
  role: 'org:admin',
  publicMetadata: { example: 'this value is updated!' },
  privateMetadata: {},
  createdAt: 1702488558867,
  updatedAt: 1707231338278,
  organization: _Organization {
    id: 'org_123',
    name: 'test',
    slug: 'test',
    imageUrl: 'https://img.clerk.com/eyJ...',
    hasImage: false,
    createdBy: 'user_123',
    createdAt: 1702488558853,
    updatedAt: 1707231200655,
    publicMetadata: { example: 'metadata' },
    privateMetadata: {},
    maxAllowedMemberships: 3,
    adminDeleteEnabled: true,
    members_count: undefined
  },
  publicUserData: _OrganizationMembershipPublicUserData {
    identifier: 'alexis@clerk.dev',
    firstName: 'Alexis',
    lastName: 'Aguilar',
    imageUrl: 'https://img.clerk.com/eyJ...',
    hasImage: true,
    userId: 'user_123'
  }
}
*/

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint PATCH/organizations/{organization_id}/memberships/{user_id}/metadata. See the BAPI reference for more information.

Feedback

What did you think of this content?

Last updated on