0

Unlink site repo

by
Published Oct 17, 2025

[Beta] Unlinks the repo from the site. This action will also: - Delete associated deploy keys - Delete outgoing webhooks for the repo - Delete the site's build hooks

Script netlify Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Netlify = {
3
  token: string;
4
};
5
/**
6
 * Unlink site repo
7
 * [Beta] Unlinks the repo from the site.
8

9
This action will also:
10
- Delete associated deploy keys
11
- Delete outgoing webhooks for the repo
12
- Delete the site's build hooks
13
 */
14
export async function main(auth: Netlify, site_id: string) {
15
  const url = new URL(
16
    `https://api.netlify.com/api/v1/sites/${site_id}/unlink_repo`,
17
  );
18

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