//native
async function apiBase(auth: RT.AdobeAcrobatSign): Promise<string> {
if (auth.base_uri) return auth.base_uri.replace(/\/+$/, "")
const r = await fetch("https://api.adobesign.com/api/rest/v6/baseUris", {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!r.ok) throw new Error(`${r.status} ${await r.text()}`)
const { apiAccessPoint } = (await r.json()) as { apiAccessPoint: string }
return apiAccessPoint.replace(/\/+$/, "")
}
/**
* Create Agreement
* 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).
*/
export async function main(
auth: RT.AdobeAcrobatSign,
agreement: {
name?: string
fileInfos?: {
transientDocumentId?: string
libraryDocumentId?: string
documentURL?: unknown
}[]
participantSetsInfo?: unknown[]
signatureType?: "ESIGN" | "WRITTEN"
state?: "DRAFT" | "AUTHORING" | "IN_PROCESS"
[key: string]: unknown
}
) {
const base = await apiBase(auth)
const url = new URL(`${base}/api/rest/v6/agreements`)
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(agreement),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 5 days ago