Update the authenticated user

**Note:** If your email is set to private and you send an `email` parameter as part of this request to update your profile, your privacy settings are still enforced: the email address will not be displayed on your public profile or via the API.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Update the authenticated user
6
 * **Note:** If your email is set to private and you send an `email` parameter as part of this request to update your profile, your privacy settings are still enforced: the email address will not be displayed on your public profile or via the API.
7
 */
8
export async function main(
9
  auth: Github,
10
  body: {
11
    bio?: string;
12
    blog?: string;
13
    company?: string;
14
    email?: string;
15
    hireable?: boolean;
16
    location?: string;
17
    name?: string;
18
    twitter_username?: string;
19
    [k: string]: unknown;
20
  }
21
) {
22
  const url = new URL(`https://api.github.com/user`);
23

24
  const response = await fetch(url, {
25
    method: "PATCH",
26
    headers: {
27
      "Content-Type": "application/json",
28
      Authorization: "Bearer " + auth.token,
29
    },
30
    body: JSON.stringify(body),
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38