0

List 1-Click Applications

by
Published Dec 20, 2024

To list all available 1-Click applications, send a GET request to `/v2/1-clicks`. The `type` may be provided as query paramater in order to restrict results to a certain type of 1-Click, for example: `/v2/1-clicks?type=droplet`. Current supported types are `kubernetes` and `droplet`. The response will be a JSON object with a key called `1_clicks`. This will be set to an array of 1-Click application data, each of which will contain the the slug and type for the 1-Click.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * List 1-Click Applications
7
 * To list all available 1-Click applications, send a GET request to `/v2/1-clicks`. The `type` may
8
be provided as query paramater in order to restrict results to a certain type of 1-Click, for
9
example: `/v2/1-clicks?type=droplet`. Current supported types are `kubernetes` and `droplet`.
10

11
The response will be a JSON object with a key called `1_clicks`. This will be set to an array of
12
1-Click application data, each of which will contain the the slug and type for the 1-Click.
13

14
 */
15
export async function main(
16
  auth: Digitalocean,
17
  type: "droplet" | "kubernetes" | undefined,
18
) {
19
  const url = new URL(`https://api.digitalocean.com/v2/1-clicks`);
20
  for (const [k, v] of [["type", type]]) {
21
    if (v !== undefined && v !== "" && k !== undefined) {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      Authorization: "Bearer " + auth.token,
29
    },
30
    body: undefined,
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