Docs

updateOrganizationMembershipMetadata()

Updates the metadata associated with a user's organization membership.

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

    The ID of the organization this membership belongs to.

  • Name
    userId
    Type
    string
    Description

    The user ID associated with the metadata being updated.

  • Name
    publicMetadata?
    Type
    Record<string, unknown>
    Description

    Metadata saved on the organization, that is visible to both your Frontend and Backend APIs.

  • Name
    privateMetadata?
    Type
    Record<string, unknown>
    Description

    Metadata saved on the organization that is only visible to your Backend API.

updateOrganizationMembershipMetadata() example

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

const organizationId = 'org_2ZUtbk2yvnFGItdeze1ivCh3uqh';

const userId = 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56';

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

console.log(response);
/* 
_OrganizationMembership {
  id: 'orgmem_2ZUtbeklm2DPSy7jsaLLwf6V8Nq',
  role: 'org:admin',
  publicMetadata: { example: 'this value is updated!' },
  privateMetadata: {},
  createdAt: 1702488558867,
  updatedAt: 1707231338278,
  organization: _Organization {
    id: 'org_2ZUtbk2yvnFGItdeze1ivCh3uqh',
    name: 'test',
    slug: 'test',
    imageUrl: 'https://img.clerk.com/eyJ0eXBlIjoiZGVmYXVsdCIsImlpZCI6Imluc18yVjdKRFdyclJwRmZFZTlqQUM2dWpSMG8xSlQiLCJyaWQiOiJvcmdfMlpVdGJrMnl2bkZHSXRkZXplMWl2Q2gzdXFoIiwiaW5pdGlhbHMiOiJUIn0',
    hasImage: false,
    createdBy: 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56',
    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/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}/metadata. See the BAPI reference for more details.

Feedback

What did you think of this content?