0

Send Envelope

by
Published 21 days ago

Promote a draft envelope (status=created) to sent.

Script docusign Verified

The script

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

3
/**
4
 * Send Envelope
5
 * Promote a draft envelope (status=created) to sent.
6
 */
7
export async function main(auth: RT.Docusign, envelope_id: string) {
8
  const url = new URL(
9
    `${auth.base_uri}/restapi/v2.1/accounts/${auth.account_id}/envelopes/${envelope_id}`,
10
  )
11

12
  const response = await fetch(url, {
13
    method: "PUT",
14
    headers: {
15
      Authorization: `Bearer ${auth.token}`,
16
      "Content-Type": "application/json",
17
      Accept: "application/json",
18
    },
19
    body: JSON.stringify({ status: "sent" }),
20
  })
21

22
  if (!response.ok) {
23
    throw new Error(`${response.status} ${await response.text()}`)
24
  }
25

26
  return await response.json()
27
}
28