0

Cancel Agreement

by
Published 4 days ago

Cancel an in-process agreement by setting its state to CANCELLED, optionally notifying the other participants.

Script adobe_acrobat_sign Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
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
 * Cancel Agreement
18
 * Cancel an in-process agreement by setting its state to CANCELLED, optionally notifying the other participants.
19
 */
20
export async function main(
21
  auth: RT.AdobeAcrobatSign,
22
  agreement_id: string,
23
  comment: string | undefined,
24
  notify_others: boolean | undefined
25
) {
26
  const base = await apiBase(auth)
27
  const url = new URL(`${base}/api/rest/v6/agreements/${agreement_id}/state`)
28

29
  const response = await fetch(url, {
30
    method: "PUT",
31
    headers: {
32
      Authorization: `Bearer ${auth.token}`,
33
      "Content-Type": "application/json",
34
      Accept: "application/json",
35
    },
36
    body: JSON.stringify({
37
      state: "CANCELLED",
38
      agreementCancellationInfo: {
39
        comment: comment ?? "",
40
        notifyOthers: notify_others ?? false,
41
      },
42
    }),
43
  })
44

45
  if (!response.ok) {
46
    throw new Error(`${response.status} ${await response.text()}`)
47
  }
48

49
  const text = await response.text()
50
  return text ? JSON.parse(text) : { success: true }
51
}
52