//native
type Digitalocean = {
token: string;
};
/**
* Update destinations for alerts
* Updates the emails and slack webhook destinations for app alerts. Emails must be associated to a user with access to the app.
*/
export async function main(
auth: Digitalocean,
app_id: string,
alert_id: string,
body: {
emails?: string[];
slack_webhooks?: { url?: string; channel?: string }[];
},
) {
const url = new URL(
`https://api.digitalocean.com/v2/apps/${app_id}/alerts/${alert_id}/destinations`,
);
const response = await fetch(url, {
method: "POST",
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