Xbase++
Xbase++
DocuSign Download Envelope Document (PDF)
See more DocuSign Examples
Retrieves the specified document from the envelope. The response body of this method is the PDF file as a byte stream. You can get the file name and document ID from the response's Content-Disposition header.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL cUrl
LOCAL oBd
LOCAL nRespStatusCode
LOCAL oMime
LOCAL cFilename
LOCAL oSbPath
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Implements the following HTTP request:
// GET /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}/documents/1
// Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header.
oJsonToken := CreateObject("Chilkat.JsonObject")
// Load a previously obtained OAuth2 access token.
nSuccess := oJsonToken:LoadFile("qa_data/tokens/docusign.json")
IF (nSuccess == 0)
? oJsonToken:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
RETURN
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")
cUrl := "https://demo.docusign.net/restapi/v2.1/accounts/{$accountId}/envelopes/{$envelopeId}/documents/1"
oBd := CreateObject("Chilkat.BinData")
nSuccess := oHttp:DownloadBd(cUrl, oBd)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
oBd:destroy()
RETURN
ENDIF
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode != 200)
? "Response Header:"
? oHttp:LastResponseHeader
// The response body contains an error message.
? oBd:GetString("utf-8")
? "Failed."
oHttp:destroy()
oJsonToken:destroy()
oBd:destroy()
RETURN
ENDIF
// The response indicated success.
// Get the filename from the Content-Disposition header and save to a file.
oMime := CreateObject("Chilkat.Mime")
oMime:LoadMime(oHttp:LastResponseHeader)
cFilename := oMime:GetHeaderFieldAttribute("Content-Disposition", "filename")
? "filename = " + cFilename
oSbPath := CreateObject("Chilkat.StringBuilder")
oSbPath:Append("C:/aaworkarea/")
oSbPath:Append(cFilename)
nSuccess := oBd:WriteFile(oSbPath:GetAsString())
IF (nSuccess == 0)
? "Failed to save to output file."
ELSE
? "Wrote " + oSbPath:GetAsString()
ENDIF
oHttp:destroy()
oJsonToken:destroy()
oBd:destroy()
oMime:destroy()
oSbPath:destroy()