Delphi DLL
Delphi DLL
Retrieve User Account Data
See more DocuSign Examples
To make an API call to the DocuSign platform, your application needs both an access token (which you obtained in the previous step), and base URI that is unique to the user on whose behalf your application is making the API call. To get the base URI, call the/oauth/userinfoendpoint, supplying your application’s access token as a header.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
jsonToken: HCkJsonObject;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
account_id: PWideChar;
is_default: Boolean;
account_name: PWideChar;
base_uri: PWideChar;
sub: PWideChar;
name: PWideChar;
given_name: PWideChar;
family_name: PWideChar;
created: PWideChar;
email: PWideChar;
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 := CkHttp_Create();
// Implements the following CURL command:
// curl --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" https://account-d.docusign.com/oauth/userinfo
// 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 := 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'));
sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://account-d.docusign.com/oauth/userinfo',sbResponseBody);
if (success = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));
respStatusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkHttp__lastResponseHeader(http));
Memo1.Lines.Add('Failed.');
Exit;
end;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "sub": "564f7988-xxxx-xxxx-xxxx-781ee556ab7a",
// "name": "Example J Smith",
// "given_name": "Example",
// "family_name": "Smith",
// "created": "2018-04-13T22:03:03.45",
// "email": "Example.Smith@exampledomain.com",
// "accounts": [
// {
// "account_id": "18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604",
// "is_default": true,
// "account_name": "ExampleAccount",
// "base_uri": "https://demo.docusign.net"
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
sub := CkJsonObject__stringOf(jResp,'sub');
name := CkJsonObject__stringOf(jResp,'name');
given_name := CkJsonObject__stringOf(jResp,'given_name');
family_name := CkJsonObject__stringOf(jResp,'family_name');
created := CkJsonObject__stringOf(jResp,'created');
email := CkJsonObject__stringOf(jResp,'email');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'accounts');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
account_id := CkJsonObject__stringOf(jResp,'accounts[i].account_id');
is_default := CkJsonObject_BoolOf(jResp,'accounts[i].is_default');
account_name := CkJsonObject__stringOf(jResp,'accounts[i].account_name');
base_uri := CkJsonObject__stringOf(jResp,'accounts[i].base_uri');
i := i + 1;
end;
CkHttp_Dispose(http);
CkJsonObject_Dispose(jsonToken);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
end;