type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Update a webhook
* Update a webhook destination.
*/
export async function main(
auth: Cloudflare,
webhook_id: string,
account_id: string,
body: { name: string; secret?: string; url: string; [k: string]: unknown }
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_id}/alerting/v3/destinations/webhooks/${webhook_id}`
);
const response = await fetch(url, {
method: "PUT",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"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 413 days ago