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 | * Get Library Document |
18 | * Retrieve the details of a single library template / document by id. |
19 | */ |
20 | export async function main( |
21 | auth: RT.AdobeAcrobatSign, |
22 | library_document_id: string |
23 | ) { |
24 | const base = await apiBase(auth) |
25 | const url = new URL( |
26 | `${base}/api/rest/v6/libraryDocuments/${library_document_id}` |
27 | ) |
28 |
|
29 | const response = await fetch(url, { |
30 | method: "GET", |
31 | headers: { |
32 | Authorization: `Bearer ${auth.token}`, |
33 | Accept: "application/json", |
34 | }, |
35 | }) |
36 |
|
37 | if (!response.ok) { |
38 | throw new Error(`${response.status} ${await response.text()}`) |
39 | } |
40 |
|
41 | return await response.json() |
42 | } |
43 |
|