13const webhookIdToDelete = "51a2064a0098b4feacadfd7db51f6a21"; // ← Change this
14
15async function listWebhooks(apiKey: string, propertyId: string): Promise<CloudbedsWebhook[]> {
16 const res = await fetch(`https://hotels.cloudbeds.com/api/v1.2/getWebhooks?propertyID=${propertyId}`, {
17 headers: { Authorization: `Bearer ${apiKey}` },
18 });
19
29}
30
31async function deleteWebhookById(apiKey: string, id: string, url: string, object: string, action: string) {
32 const body = new URLSearchParams({
33 subscriptionID: id,
37 });
38
39 const res = await fetch("https://hotels.cloudbeds.com/api/v1.2/deleteWebhook", {
40 method: "POST",
41 headers: {
42 Authorization: `Bearer ${apiKey}`,
43 "Content-Type": "application/x-www-form-urlencoded",
44 },
54export default async function() {
55 const user = await blob.getJSON(`cloudbeds_user_${userId}`);
56 const apiKey = user?.cloudbedsAccounts?.[propertyId]?.apiKey;
57 if (!apiKey) throw new Error(`Missing API key for user ${userId} and property ${propertyId}`);
58
59 const webhooks = await listWebhooks(apiKey, propertyId);
60 const match = webhooks.find(w => w.id === webhookIdToDelete);
61 if (!match) throw new Error(`Webhook ${webhookIdToDelete} not found on property ${propertyId}`);
62
63 await deleteWebhookById(
64 apiKey,
65 match.id,
66 match.subscriptionData.url,