0

List Documents

by
Published 21 days ago

List documents belonging to an envelope.

Script docusign Verified

The script

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

3
/**
4
 * List Documents
5
 * List documents belonging to an envelope.
6
 */
7
export async function main(
8
  auth: RT.Docusign,
9
  envelope_id: string,
10
  include_metadata: boolean | undefined,
11
) {
12
  const url = new URL(
13
    `${auth.base_uri}/restapi/v2.1/accounts/${auth.account_id}/envelopes/${envelope_id}/documents`,
14
  )
15
  if (include_metadata !== undefined) {
16
    url.searchParams.append("include_metadata", String(include_metadata))
17
  }
18

19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      Authorization: `Bearer ${auth.token}`,
23
      Accept: "application/json",
24
    },
25
  })
26

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

31
  return await response.json()
32
}
33