0

Get Envelope

by
Published 21 days ago

Fetch envelope status and metadata by ID.

Script docusign Verified

The script

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

3
/**
4
 * Get Envelope
5
 * Fetch envelope status and metadata by ID.
6
 */
7
export async function main(
8
  auth: RT.Docusign,
9
  envelope_id: string,
10
  advanced_update: boolean | undefined,
11
  include: string | undefined,
12
) {
13
  const url = new URL(
14
    `${auth.base_uri}/restapi/v2.1/accounts/${auth.account_id}/envelopes/${envelope_id}`,
15
  )
16
  if (advanced_update !== undefined) {
17
    url.searchParams.append("advanced_update", String(advanced_update))
18
  }
19
  if (include !== undefined && include !== "") {
20
    url.searchParams.append("include", include)
21
  }
22

23
  const response = await fetch(url, {
24
    method: "GET",
25
    headers: {
26
      Authorization: `Bearer ${auth.token}`,
27
      Accept: "application/json",
28
    },
29
  })
30

31
  if (!response.ok) {
32
    throw new Error(`${response.status} ${await response.text()}`)
33
  }
34

35
  return await response.json()
36
}
37