0

Create a Project

by
Published Dec 20, 2024

To create a project, send a POST request to `/v2/projects`.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Create a Project
7
 * To create a project, send a POST request to `/v2/projects`.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  body: {
12
    id?: string;
13
    owner_uuid?: string;
14
    owner_id?: number;
15
    name?: string;
16
    description?: string;
17
    purpose?: string;
18
    environment?: "Development" | "Staging" | "Production";
19
    created_at?: string;
20
    updated_at?: string;
21
  },
22
) {
23
  const url = new URL(`https://api.digitalocean.com/v2/projects`);
24

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