Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Docusign: Return Brand Data Associated with a User
See more DocuSign Examples
Demonstrates a call using an OAuth2 access token in combination with the account ID for which we have authorization.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;
json: TJsonObject;
respStatusCode: Integer;
brandCompany: string;
brandId: string;
brandName: string;
errorDetailsErrorCode: string;
errorDetailsMessage: string;
isOverridingCompanyName: string;
isSendingDefault: string;
isSigningDefault: string;
logosPrimary: string;
logosSecondary: string;
logosEmail: string;
resourcesEmail: string;
resourcesSending: string;
resourcesSigning: string;
resourcesSigningCaptive: string;
j: Integer;
count_j: Integer;
linkType: string;
urlOrMailTo: string;
linkText: string;
showLink: string;
emailContentType: string;
content: string;
emailToLink: string;
recipientBrandIdDefault: string;
senderBrandIdDefault: 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 CURL command:
// curl --request GET https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// 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 an account ID obtained from DocuSign Get User Account Data
sbResponseBody := TStringBuilder.Create;
success := http.QuickGetSb('https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands',sbResponseBody);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
json := TJsonObject.Create;
json.LoadSb(sbResponseBody);
json.EmitCompact := False;
WriteLn('Response Body:');
WriteLn(json.Emit());
respStatusCode := http.LastStatus;
WriteLn('Response Status Code = ' + respStatusCode);
if (respStatusCode >= 400) then
begin
WriteLn('Response Header:');
WriteLn(http.LastHeader);
WriteLn('Failed.');
Exit;
end;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "recipientBrandIdDefault": "sample string 1",
// "senderBrandIdDefault": "sample string 2",
// "brands": [
// {
// "brandCompany": "sample string 1",
// "brandId": "sample string 2",
// "brandName": "sample string 3",
// "colors": [
// {}
// ],
// "errorDetails": {
// "errorCode": "sample string 1",
// "message": "sample string 2"
// },
// "isOverridingCompanyName": "sample string 4",
// "isSendingDefault": "sample string 5",
// "isSigningDefault": "sample string 6",
// "landingPages": [
// {}
// ],
// "links": [
// {
// "linkType": "sample string 1",
// "urlOrMailTo": "sample string 2",
// "linkText": "sample string 3",
// "showLink": "sample string 4"
// }
// ],
// "emailContent": [
// {
// "emailContentType": "sample string 1",
// "content": "sample string 2",
// "emailToLink": "sample string 3",
// "linkText": "sample string 4"
// }
// ],
// "logos": {
// "primary": "sample string 1",
// "secondary": "sample string 2",
// "email": "sample string 3"
// },
// "resources": {
// "email": "sample string 1",
// "sending": "sample string 2",
// "signing": "sample string 3",
// "signingCaptive": "sample string 4"
// }
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
recipientBrandIdDefault := json.StringOf('recipientBrandIdDefault');
senderBrandIdDefault := json.StringOf('senderBrandIdDefault');
i := 0;
count_i := json.SizeOfArray('brands');
while i < count_i do
begin
json.I := i;
brandCompany := json.StringOf('brands[i].brandCompany');
brandId := json.StringOf('brands[i].brandId');
brandName := json.StringOf('brands[i].brandName');
errorDetailsErrorCode := json.StringOf('brands[i].errorDetails.errorCode');
errorDetailsMessage := json.StringOf('brands[i].errorDetails.message');
isOverridingCompanyName := json.StringOf('brands[i].isOverridingCompanyName');
isSendingDefault := json.StringOf('brands[i].isSendingDefault');
isSigningDefault := json.StringOf('brands[i].isSigningDefault');
logosPrimary := json.StringOf('brands[i].logos.primary');
logosSecondary := json.StringOf('brands[i].logos.secondary');
logosEmail := json.StringOf('brands[i].logos.email');
resourcesEmail := json.StringOf('brands[i].resources.email');
resourcesSending := json.StringOf('brands[i].resources.sending');
resourcesSigning := json.StringOf('brands[i].resources.signing');
resourcesSigningCaptive := json.StringOf('brands[i].resources.signingCaptive');
j := 0;
count_j := json.SizeOfArray('brands[i].colors');
while j < count_j do
begin
json.J := j;
j := j + 1;
end;
j := 0;
count_j := json.SizeOfArray('brands[i].landingPages');
while j < count_j do
begin
json.J := j;
j := j + 1;
end;
j := 0;
count_j := json.SizeOfArray('brands[i].links');
while j < count_j do
begin
json.J := j;
linkType := json.StringOf('brands[i].links[j].linkType');
urlOrMailTo := json.StringOf('brands[i].links[j].urlOrMailTo');
linkText := json.StringOf('brands[i].links[j].linkText');
showLink := json.StringOf('brands[i].links[j].showLink');
j := j + 1;
end;
j := 0;
count_j := json.SizeOfArray('brands[i].emailContent');
while j < count_j do
begin
json.J := j;
emailContentType := json.StringOf('brands[i].emailContent[j].emailContentType');
content := json.StringOf('brands[i].emailContent[j].content');
emailToLink := json.StringOf('brands[i].emailContent[j].emailToLink');
linkText := json.StringOf('brands[i].emailContent[j].linkText');
j := j + 1;
end;
i := i + 1;
end;
http.Free;
jsonToken.Free;
sbResponseBody.Free;
json.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.