0

Cancel an organization invitation

by
Published Oct 25, 2023

Cancel an organization invitation. In order to cancel an organization invitation, the authenticated user must be an organization owner. This endpoint triggers [notifications](https://docs.github.com/github/managing-subscriptions-and-notifications-on-github/about-notifications).

Script github Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Cancel an organization invitation
6
 * Cancel an organization invitation. In order to cancel an organization invitation, the authenticated user must be an organization owner.
7

8
This endpoint triggers [notifications](https://docs.github.com/github/managing-subscriptions-and-notifications-on-github/about-notifications).
9
 */
10
export async function main(auth: Github, org: string, invitation_id: string) {
11
  const url = new URL(
12
    `https://api.github.com/orgs/${org}/invitations/${invitation_id}`
13
  );
14

15
  const response = await fetch(url, {
16
    method: "DELETE",
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