![]() |
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(Delphi DLL) DocuSign Download Envelope Document (PDF)See more DocuSign ExamplesRetrieves 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.For more information, see https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopedocuments/get/
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, BinData, StringBuilder, Mime, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; success: Boolean; jsonToken: HCkJsonObject; url: PWideChar; bd: HCkBinData; respStatusCode: Integer; mime: HCkMime; filename: PWideChar; sbPath: HCkStringBuilder; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); // Implements the following HTTP request: // GET /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}/documents/1 // Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header. jsonToken := CkJsonObject_Create(); // Load a previously obtained OAuth2 access token. success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/docusign.json'); if (success = False) then begin Memo1.Lines.Add(CkJsonObject__lastErrorText(jsonToken)); Exit; end; CkHttp_putAuthToken(http,CkJsonObject__stringOf(jsonToken,'access_token')); // Use your account ID and a valid envelopeId here: CkHttp_SetUrlVar(http,'accountId','7f3f65ed-5e87-418d-94c1-92499ddc8252'); CkHttp_SetUrlVar(http,'envelopeId','90d7e40a-b4bd-4ccd-bf38-c80e37954a13'); url := 'https://demo.docusign.net/restapi/v2.1/accounts/{$accountId}/envelopes/{$envelopeId}/documents/1'; bd := CkBinData_Create(); success := CkHttp_DownloadBd(http,url,bd); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; respStatusCode := CkHttp_getLastStatus(http); Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode <> 200) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkHttp__lastResponseHeader(http)); // The response body contains an error message. Memo1.Lines.Add(CkBinData__getString(bd,'utf-8')); Memo1.Lines.Add('Failed.'); Exit; end; // The response indicated success. // Get the filename from the Content-Disposition header and save to a file. mime := CkMime_Create(); CkMime_LoadMime(mime,CkHttp__lastResponseHeader(http)); filename := CkMime__getHeaderFieldAttribute(mime,'Content-Disposition','filename'); Memo1.Lines.Add('filename = ' + filename); sbPath := CkStringBuilder_Create(); CkStringBuilder_Append(sbPath,'C:/aaworkarea/'); CkStringBuilder_Append(sbPath,filename); success := CkBinData_WriteFile(bd,CkStringBuilder__getAsString(sbPath)); if (success = False) then begin Memo1.Lines.Add('Failed to save to output file.'); end else begin Memo1.Lines.Add('Wrote ' + CkStringBuilder__getAsString(sbPath)); end; CkHttp_Dispose(http); CkJsonObject_Dispose(jsonToken); CkBinData_Dispose(bd); CkMime_Dispose(mime); CkStringBuilder_Dispose(sbPath); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.