//native
type Clerk = {
apiKey: string;
};
/**
* Merge and update organization membership metadata
* Update an organization membership's metadata attributes 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`.
*/
export async function main(
auth: Clerk,
organization_id: string,
user_id: string,
body: { public_metadata?: {}; private_metadata?: {} },
) {
const url = new URL(
`https://api.clerk.com/v1/organizations/${organization_id}/memberships/${user_id}/metadata`,
);
const response = await fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago