0

Update Trigger

by
Published Dec 20, 2024

Updates the details of the given trigger. To update a trigger, send a PUT request to `/v2/functions/namespaces/$NAMESPACE_ID/triggers/$TRIGGER_NAME` with new values for the `is_enabled ` or `scheduled_details` properties.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Update Trigger
7
 * Updates the details of the given trigger. To update a trigger, send a PUT request to `/v2/functions/namespaces/$NAMESPACE_ID/triggers/$TRIGGER_NAME` with new values for the `is_enabled ` or `scheduled_details` properties.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  namespace_id: string,
12
  trigger_name: string,
13
  body: {
14
    is_enabled?: false | true;
15
    scheduled_details?: { cron: string; body?: { name?: string } };
16
  },
17
) {
18
  const url = new URL(
19
    `https://api.digitalocean.com/v2/functions/namespaces/${namespace_id}/triggers/${trigger_name}`,
20
  );
21

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