Edits history of script submission #22303 for ' Get Envelope (docusign)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Envelope
     * Fetch envelope status and metadata by ID.
     */
    export async function main(
      auth: RT.Docusign,
      envelope_id: string,
      advanced_update: boolean | undefined,
      include: string | undefined,
    ) {
      const url = new URL(
        `${auth.base_uri}/restapi/v2.1/accounts/${auth.account_id}/envelopes/${envelope_id}`,
      )
      if (advanced_update !== undefined) {
        url.searchParams.append("advanced_update", String(advanced_update))
      }
      if (include !== undefined && include !== "") {
        url.searchParams.append("include", include)
      }
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 22 days ago