0

Delete Trigger

by
Published Dec 20, 2024

Deletes the given trigger. To delete trigger, send a DELETE request to `/v2/functions/namespaces/$NAMESPACE_ID/triggers/$TRIGGER_NAME`. A successful deletion returns a 204 response.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Delete Trigger
7
 * Deletes the given trigger.
8
To delete trigger, send a DELETE request to `/v2/functions/namespaces/$NAMESPACE_ID/triggers/$TRIGGER_NAME`.
9
A successful deletion returns a 204 response.
10
 */
11
export async function main(
12
  auth: Digitalocean,
13
  namespace_id: string,
14
  trigger_name: string,
15
) {
16
  const url = new URL(
17
    `https://api.digitalocean.com/v2/functions/namespaces/${namespace_id}/triggers/${trigger_name}`,
18
  );
19

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