1 | |
2 |
|
3 | async function apiBase(auth: RT.AdobeAcrobatSign): Promise<string> { |
4 | if (auth.base_uri) return auth.base_uri.replace(/\/+$/, "") |
5 | const r = await fetch("https://api.adobesign.com/api/rest/v6/baseUris", { |
6 | headers: { |
7 | Authorization: `Bearer ${auth.token}`, |
8 | Accept: "application/json", |
9 | }, |
10 | }) |
11 | if (!r.ok) throw new Error(`${r.status} ${await r.text()}`) |
12 | const { apiAccessPoint } = (await r.json()) as { apiAccessPoint: string } |
13 | return apiAccessPoint.replace(/\/+$/, "") |
14 | } |
15 |
|
16 | |
17 | * Delete Webhook |
18 | * Permanently delete a registered webhook by id. |
19 | */ |
20 | export async function main(auth: RT.AdobeAcrobatSign, webhook_id: string) { |
21 | const base = await apiBase(auth) |
22 | const url = new URL(`${base}/api/rest/v6/webhooks/${webhook_id}`) |
23 |
|
24 | const response = await fetch(url, { |
25 | method: "DELETE", |
26 | headers: { |
27 | Authorization: `Bearer ${auth.token}`, |
28 | Accept: "application/json", |
29 | }, |
30 | }) |
31 |
|
32 | if (!response.ok) { |
33 | throw new Error(`${response.status} ${await response.text()}`) |
34 | } |
35 |
|
36 | if (response.status === 204) return { success: true } |
37 | const text = await response.text() |
38 | return text ? JSON.parse(text) : { success: true } |
39 | } |
40 |
|