0

Set public organization membership for the authenticated user

by
Published Oct 25, 2023

The user can publicize their own membership. (A user cannot publicize the membership for another user.) Note that you'll need to set `Content-Length` to zero when calling out to this endpoint. For more information, see "[HTTP verbs](https://docs.github.com/rest/overview/resources-in-the-rest-api#http-verbs)."

Script github Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Set public organization membership for the authenticated user
6
 * The user can publicize their own membership. (A user cannot publicize the membership for another user.)
7

8
Note that you'll need to set `Content-Length` to zero when calling out to this endpoint. For more information, see "[HTTP verbs](https://docs.github.com/rest/overview/resources-in-the-rest-api#http-verbs)."
9
 */
10
export async function main(auth: Github, org: string, username: string) {
11
  const url = new URL(
12
    `https://api.github.com/orgs/${org}/public_members/${username}`
13
  );
14

15
  const response = await fetch(url, {
16
    method: "PUT",
17
    headers: {
18
      Authorization: "Bearer " + auth.token,
19
    },
20
    body: undefined,
21
  });
22
  if (!response.ok) {
23
    const text = await response.text();
24
    throw new Error(`${response.status} ${text}`);
25
  }
26
  return await response.text();
27
}
28