0

Patch a Project

by
Published Dec 20, 2024

To update only specific attributes of a project, send a PATCH request to `/v2/projects/$PROJECT_ID`. At least one of the following attributes needs to be sent.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Patch a Project
7
 * To update only specific attributes of a project, send a PATCH request to `/v2/projects/$PROJECT_ID`. At least one of the following attributes needs to be sent.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  project_id: string,
12
  body: {
13
    id?: string;
14
    owner_uuid?: string;
15
    owner_id?: number;
16
    name?: string;
17
    description?: string;
18
    purpose?: string;
19
    environment?: "Development" | "Staging" | "Production";
20
    created_at?: string;
21
    updated_at?: string;
22
  } & { is_default?: false | true },
23
) {
24
  const url = new URL(`https://api.digitalocean.com/v2/projects/${project_id}`);
25

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