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 | * Create Agreement |
18 | * Create and send an agreement for signature. Reference an uploaded transientDocumentId or a libraryDocumentId in fileInfos, list recipients in participantSetsInfo, and set state to IN_PROCESS to send (DRAFT to save, AUTHORING to add fields first). |
19 | */ |
20 | export async function main( |
21 | auth: RT.AdobeAcrobatSign, |
22 | agreement: { |
23 | name?: string |
24 | fileInfos?: { |
25 | transientDocumentId?: string |
26 | libraryDocumentId?: string |
27 | documentURL?: unknown |
28 | }[] |
29 | participantSetsInfo?: unknown[] |
30 | signatureType?: "ESIGN" | "WRITTEN" |
31 | state?: "DRAFT" | "AUTHORING" | "IN_PROCESS" |
32 | [key: string]: unknown |
33 | } |
34 | ) { |
35 | const base = await apiBase(auth) |
36 | const url = new URL(`${base}/api/rest/v6/agreements`) |
37 |
|
38 | const response = await fetch(url, { |
39 | method: "POST", |
40 | headers: { |
41 | Authorization: `Bearer ${auth.token}`, |
42 | "Content-Type": "application/json", |
43 | Accept: "application/json", |
44 | }, |
45 | body: JSON.stringify(agreement), |
46 | }) |
47 |
|
48 | if (!response.ok) { |
49 | throw new Error(`${response.status} ${await response.text()}`) |
50 | } |
51 |
|
52 | return await response.json() |
53 | } |
54 |
|