1 | |
2 | type Persona = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Disable a Webhook |
7 | * Disables a webhook. |
8 | */ |
9 | export async function main( |
10 | auth: Persona, |
11 | webhook_id: string, |
12 | include?: string, |
13 | fields?: string, |
14 | Key_Inflection?: string, |
15 | Idempotency_Key?: string, |
16 | Persona_Version?: string, |
17 | ) { |
18 | const url = new URL( |
19 | `https://api.withpersona.com/api/v1/webhooks/${webhook_id}/disable`, |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["include", include], |
23 | ["fields", fields], |
24 | ]) { |
25 | if (v !== undefined && v !== "" && k !== undefined) { |
26 | url.searchParams.append(k, v); |
27 | } |
28 | } |
29 | const headers: Record<string, string> = { |
30 | Authorization: `Bearer ${auth.apiKey}`, |
31 | }; |
32 | if (Key_Inflection) { |
33 | headers["Key-Inflection"] = Key_Inflection; |
34 | } |
35 | if (Idempotency_Key) { |
36 | headers["Idempotency-Key"] = Idempotency_Key; |
37 | } |
38 | if (Persona_Version) { |
39 | headers["Persona-Version"] = Persona_Version; |
40 | } |
41 | const response = await fetch(url, { |
42 | method: "POST", |
43 | headers, |
44 | body: undefined, |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|