Sample code for 30+ languages & platforms
AutoIt

DocuSign List Envelope Documents

See more DocuSign Examples

Retrieve a list of all documents within a specific envelope.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat.Http")

; Implements the following HTTP request:
; GET /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}/documents

; Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header.
$oJsonToken = ObjCreate("Chilkat.JsonObject")
; Load a previously obtained OAuth2 access token.
$bSuccess = $oJsonToken.LoadFile("qa_data/tokens/docusign.json")
If ($bSuccess = False) Then
    ConsoleWrite($oJsonToken.LastErrorText & @CRLF)
    Exit
EndIf

$oHttp.AuthToken = $oJsonToken.StringOf("access_token")

; Use your account ID and a valid envelopeId here:
$oHttp.SetUrlVar("accountId","7f3f65ed-5e87-418d-94c1-92499ddc8252")
$oHttp.SetUrlVar("envelopeId","90d7e40a-b4bd-4ccd-bf38-c80e37954a13")

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://demo.docusign.net/restapi/v2.1/accounts/{$accountId}/envelopes/{$envelopeId}/documents",$oSbResponseBody)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oHttp.LastHeader & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)

; {
;   "envelopeId": "90d7e40a-b4bd-4ccd-bf38-c80e37954a13",
;   "envelopeDocuments": [
;     {
;       "documentId": "1",
;       "documentIdGuid": "ca1d3cc6-9bc3-48d6-a5d8-a85d9acdcde1",
;       "name": "helloWorld.pdf",
;       "type": "content",
;       "uri": "/envelopes/90d7e40a-b4bd-4ccd-bf38-c80e37954a13/documents/1",
;       "order": "1",
;       "pages": [
;         {
;           "pageId": "fbf93a36-6b60-484d-94bd-ee3c08c0a546",
;           "sequence": "1",
;           "height": "842",
;           "width": "595",
;           "dpi": "72"
;         }
;       ],
;       "availableDocumentTypes": [
;         {
;           "type": "electronic",
;           "isDefault": "true"
;         }
;       ],
;       "display": "inline",
;       "includeInDownload": "true",
;       "signerMustAcknowledge": "no_interaction",
;       "templateRequired": "false",
;       "authoritativeCopy": "false"
;     },
;     {
;       "documentId": "certificate",
;       "documentIdGuid": "7479a5de-8d91-44a2-bc33-b76a9ba0f6e2",
;       "name": "Summary",
;       "type": "summary",
;       "uri": "/envelopes/90d7e40a-b4bd-4ccd-bf38-c80e37954a13/documents/certificate",
;       "order": "999",
;       "availableDocumentTypes": [
;         {
;           "type": "electronic",
;           "isDefault": "true"
;         }
;       ],
;       "display": "inline",
;       "includeInDownload": "true",
;       "signerMustAcknowledge": "no_interaction",
;       "templateRequired": "false",
;       "authoritativeCopy": "false"
;     }
;   ]
; }

; Sample code for parsing the JSON response...
; Use the following online tool to generate parsing code from sample JSON:
; Generate Parsing Code from JSON

Local $sDocumentId
Local $sDocumentIdGuid
Local $sName
Local $sV_type
Local $sUri
Local $sOrder
Local $sDisplay
Local $sIncludeInDownload
Local $signerMustAcknowledge
Local $sTemplateRequired
Local $sAuthoritativeCopy
Local $iJ
Local $iCount_j
Local $sPageId
Local $sequence
Local $sHeight
Local $sWidth
Local $sDpi
Local $sIsDefault

Local $sEnvelopeId = $oJResp.StringOf("envelopeId")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("envelopeDocuments")
While $i < $iCount_i
    $oJResp.I = $i
    $sDocumentId = $oJResp.StringOf("envelopeDocuments[i].documentId")
    $sDocumentIdGuid = $oJResp.StringOf("envelopeDocuments[i].documentIdGuid")
    $sName = $oJResp.StringOf("envelopeDocuments[i].name")
    $sV_type = $oJResp.StringOf("envelopeDocuments[i].type")
    $sUri = $oJResp.StringOf("envelopeDocuments[i].uri")
    $sOrder = $oJResp.StringOf("envelopeDocuments[i].order")
    $sDisplay = $oJResp.StringOf("envelopeDocuments[i].display")
    $sIncludeInDownload = $oJResp.StringOf("envelopeDocuments[i].includeInDownload")
    $signerMustAcknowledge = $oJResp.StringOf("envelopeDocuments[i].signerMustAcknowledge")
    $sTemplateRequired = $oJResp.StringOf("envelopeDocuments[i].templateRequired")
    $sAuthoritativeCopy = $oJResp.StringOf("envelopeDocuments[i].authoritativeCopy")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("envelopeDocuments[i].pages")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sPageId = $oJResp.StringOf("envelopeDocuments[i].pages[j].pageId")
        $sequence = $oJResp.StringOf("envelopeDocuments[i].pages[j].sequence")
        $sHeight = $oJResp.StringOf("envelopeDocuments[i].pages[j].height")
        $sWidth = $oJResp.StringOf("envelopeDocuments[i].pages[j].width")
        $sDpi = $oJResp.StringOf("envelopeDocuments[i].pages[j].dpi")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("envelopeDocuments[i].availableDocumentTypes")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sV_type = $oJResp.StringOf("envelopeDocuments[i].availableDocumentTypes[j].type")
        $sIsDefault = $oJResp.StringOf("envelopeDocuments[i].availableDocumentTypes[j].isDefault")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend