Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
DocuSign List Folder Items
See more DocuSign Examples
Retrieves a list of the envelopes in the specified folder.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.StringBuilder,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
jsonToken: TJsonObject;
sbResponseBody: TStringBuilder;
jResp: TJsonObject;
respStatusCode: Integer;
ownerName: string;
envelopeId: string;
envelopeUri: string;
status: string;
senderName: string;
senderEmail: string;
createdDateTime: string;
sentDateTime: string;
completedDateTime: string;
subject: string;
templateId: string;
name: string;
shared: string;
password: string;
description: string;
lastModified: string;
pageCount: Integer;
uri: string;
is21CFRPart11: string;
isSignatureProviderEnvelope: string;
j: Integer;
count_j: Integer;
fieldId: string;
show: string;
required: string;
value: string;
configurationType: string;
errorDetailsErrorCode: string;
errorDetailsMessage: string;
resultSetSize: string;
startPosition: string;
endPosition: string;
totalSetSize: string;
previousUri: string;
nextUri: string;
i: Integer;
count_i: Integer;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := THttp.Create;
// Implements the following HTTP request:
// GET /restapi/v2.1/accounts/{accountId}/folders/{folderId}
// Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header.
jsonToken := TJsonObject.Create;
// Load a previously obtained OAuth2 access token.
success := jsonToken.LoadFile('qa_data/tokens/docusign.json');
if (success = False) then
begin
WriteLn(jsonToken.LastErrorText);
Exit;
end;
http.AuthToken := jsonToken.StringOf('access_token');
// Use your account ID and a valid folderId here:
http.SetUrlVar('accountId','7f3f65ed-5e87-418d-94c1-92499ddc8252');
http.SetUrlVar('folderId','94644782-31b7-4f82-a2c1-26d8a9306f8c');
sbResponseBody := TStringBuilder.Create;
success := http.QuickGetSb('https://demo.docusign.net/restapi/v2.1/accounts/{$accountId}/folders/{$folderId}',sbResponseBody);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
jResp := TJsonObject.Create;
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact := False;
WriteLn('Response Body:');
WriteLn(jResp.Emit());
respStatusCode := http.LastStatus;
WriteLn('Response Status Code = ' + respStatusCode);
if (respStatusCode >= 400) then
begin
WriteLn('Response Header:');
WriteLn(http.LastResponseHeader);
WriteLn('Failed.');
Exit;
end;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "resultSetSize": "sample string 1",
// "startPosition": "sample string 2",
// "endPosition": "sample string 3",
// "totalSetSize": "sample string 4",
// "previousUri": "sample string 5",
// "nextUri": "sample string 6",
// "folderItems": [
// {
// "ownerName": "sample string 1",
// "envelopeId": "sample string 2",
// "envelopeUri": "sample string 3",
// "status": "sample string 4",
// "senderName": "sample string 5",
// "senderEmail": "sample string 6",
// "createdDateTime": "sample string 7",
// "sentDateTime": "sample string 8",
// "completedDateTime": "sample string 9",
// "subject": "sample string 10",
// "templateId": "sample string 11",
// "name": "sample string 12",
// "shared": "sample string 13",
// "password": "sample string 14",
// "description": "sample string 15",
// "lastModified": "sample string 16",
// "pageCount": 17,
// "uri": "sample string 18",
// "is21CFRPart11": "sample string 19",
// "isSignatureProviderEnvelope": "sample string 20",
// "customFields": [
// {
// "fieldId": "sample string 1",
// "name": "sample string 2",
// "show": "sample string 3",
// "required": "sample string 4",
// "value": "sample string 5",
// "configurationType": "sample string 6",
// "errorDetails": {
// "errorCode": "sample string 1",
// "message": "sample string 2"
// }
// }
// ]
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
resultSetSize := jResp.StringOf('resultSetSize');
startPosition := jResp.StringOf('startPosition');
endPosition := jResp.StringOf('endPosition');
totalSetSize := jResp.StringOf('totalSetSize');
previousUri := jResp.StringOf('previousUri');
nextUri := jResp.StringOf('nextUri');
i := 0;
count_i := jResp.SizeOfArray('folderItems');
while i < count_i do
begin
jResp.I := i;
ownerName := jResp.StringOf('folderItems[i].ownerName');
envelopeId := jResp.StringOf('folderItems[i].envelopeId');
envelopeUri := jResp.StringOf('folderItems[i].envelopeUri');
status := jResp.StringOf('folderItems[i].status');
senderName := jResp.StringOf('folderItems[i].senderName');
senderEmail := jResp.StringOf('folderItems[i].senderEmail');
createdDateTime := jResp.StringOf('folderItems[i].createdDateTime');
sentDateTime := jResp.StringOf('folderItems[i].sentDateTime');
completedDateTime := jResp.StringOf('folderItems[i].completedDateTime');
subject := jResp.StringOf('folderItems[i].subject');
templateId := jResp.StringOf('folderItems[i].templateId');
name := jResp.StringOf('folderItems[i].name');
shared := jResp.StringOf('folderItems[i].shared');
password := jResp.StringOf('folderItems[i].password');
description := jResp.StringOf('folderItems[i].description');
lastModified := jResp.StringOf('folderItems[i].lastModified');
pageCount := jResp.IntOf('folderItems[i].pageCount');
uri := jResp.StringOf('folderItems[i].uri');
is21CFRPart11 := jResp.StringOf('folderItems[i].is21CFRPart11');
isSignatureProviderEnvelope := jResp.StringOf('folderItems[i].isSignatureProviderEnvelope');
j := 0;
count_j := jResp.SizeOfArray('folderItems[i].customFields');
while j < count_j do
begin
jResp.J := j;
fieldId := jResp.StringOf('folderItems[i].customFields[j].fieldId');
name := jResp.StringOf('folderItems[i].customFields[j].name');
show := jResp.StringOf('folderItems[i].customFields[j].show');
required := jResp.StringOf('folderItems[i].customFields[j].required');
value := jResp.StringOf('folderItems[i].customFields[j].value');
configurationType := jResp.StringOf('folderItems[i].customFields[j].configurationType');
errorDetailsErrorCode := jResp.StringOf('folderItems[i].customFields[j].errorDetails.errorCode');
errorDetailsMessage := jResp.StringOf('folderItems[i].customFields[j].errorDetails.message');
j := j + 1;
end;
i := i + 1;
end;
http.Free;
jsonToken.Free;
sbResponseBody.Free;
jResp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.