0

Void Envelope

by
Published 21 days ago

Void an in-flight envelope with a required reason.

Script docusign Verified

The script

Submitted by hugo989 Bun
Verified 22 days ago
1
//native
2

3
/**
4
 * Void Envelope
5
 * Void an in-flight envelope with a required reason.
6
 */
7
export async function main(
8
  auth: RT.Docusign,
9
  envelope_id: string,
10
  voided_reason: string,
11
) {
12
  const url = new URL(
13
    `${auth.base_uri}/restapi/v2.1/accounts/${auth.account_id}/envelopes/${envelope_id}`,
14
  )
15

16
  const response = await fetch(url, {
17
    method: "PUT",
18
    headers: {
19
      Authorization: `Bearer ${auth.token}`,
20
      "Content-Type": "application/json",
21
      Accept: "application/json",
22
    },
23
    body: JSON.stringify({ status: "voided", voidedReason: voided_reason }),
24
  })
25

26
  if (!response.ok) {
27
    throw new Error(`${response.status} ${await response.text()}`)
28
  }
29

30
  return await response.json()
31
}
32