Edits history of script submission #22301 for ' Create Envelope (docusign)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Envelope
     * Create an envelope from a JSON envelope definition. Set status to "sent" to send immediately, or "created" to save as draft.
     */
    export async function main(
      auth: RT.Docusign,
      envelope_definition: {
        emailSubject?: string
        emailBlurb?: string
        status?: "sent" | "created"
        documents?: unknown[]
        recipients?: unknown
        templateId?: string
        templateRoles?: unknown[]
        [key: string]: unknown
      },
    ) {
      const url = new URL(
        `${auth.base_uri}/restapi/v2.1/accounts/${auth.account_id}/envelopes`,
      )
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify(envelope_definition),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 22 days ago