Edits history of script submission #11029 for ' Update Trigger (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Update Trigger
     * 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.
     */
    export async function main(
      auth: Digitalocean,
      namespace_id: string,
      trigger_name: string,
      body: {
        is_enabled?: false | true;
        scheduled_details?: { cron: string; body?: { name?: string } };
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/functions/namespaces/${namespace_id}/triggers/${trigger_name}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 536 days ago