Sample code for 30+ languages & platforms
Delphi DLL

Yousign: Making your first API call

See more Yousign Examples

Demonstrates making the simplest of calls to test your API key. This example tests using the sandbox URLs.

Chilkat Delphi DLL Downloads

Delphi DLL
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;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
name: PWideChar;
strVal: PWideChar;
id: PWideChar;
firstname: PWideChar;
lastname: PWideChar;
email: PWideChar;
title: PWideChar;
phone: PWideChar;
status: PWideChar;
organization: PWideChar;
permission: PWideChar;
groupId: PWideChar;
groupName: PWideChar;
createdAt: PWideChar;
updatedAt: PWideChar;
deleted: Boolean;
deletedAt: PWideChar;
inweboUserRequest: PWideChar;
samlNameId: PWideChar;
defaultSignImage: PWideChar;
notificationsProcedure: Boolean;
fastSign: Boolean;
fullName: 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 --location --request GET 'https://staging-api.yousign.com/users' \
// --header 'Authorization: Bearer YOUR_API_KEY' \
// --header 'Content-Type: application/json'

// 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 YOUR_API_KEY" header.
CkHttp_putAuthToken(http,'YOUR_API_KEY');
CkHttp_SetRequestHeader(http,'Content-Type','application/json');

sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://staging-api.yousign.com/users',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__lastHeader(http));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "id": "/users/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
//   "firstname": "John",
//   "lastname": "Doe",
//   "email": "john.doe@yousign.fr",
//   "title": "Developer",
//   "phone": "+33612345678",
//   "status": "activated",
//   "organization": "/organizations/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
//   "workspaces": [
//     {
//       "id": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
//       "name": "Acme"
//     }
//   ],
//   "permission": "ROLE_ADMIN",
//   "group": {
//     "id": "/user_groups/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
//     "name": "Administrateur",
//     "permissions": [
//       "procedure_write",
//       "procedure_template_write",
//       "procedure_create_from_template",
//       "contact",
//       "sign",
//       "organization",
//       "user",
//       "api_key",
//       "procedure_custom_field",
//       "signature_ui",
//       "certificate",
//       "archive"
//     ]
//   },
//   "createdAt": "2018-12-01T09:42:25+01:00",
//   "updatedAt": "2018-12-01T09:42:25+01:00",
//   "deleted": false,
//   "deletedAt": null,
//   "config": [
//   ],
//   "inweboUserRequest": null,
//   "samlNameId": null,
//   "defaultSignImage": null,
//   "notifications": {
//     "procedure": true
//   },
//   "fastSign": false,
//   "fullName": "John Doe"
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

id := CkJsonObject__stringOf(jResp,'id');
firstname := CkJsonObject__stringOf(jResp,'firstname');
lastname := CkJsonObject__stringOf(jResp,'lastname');
email := CkJsonObject__stringOf(jResp,'email');
title := CkJsonObject__stringOf(jResp,'title');
phone := CkJsonObject__stringOf(jResp,'phone');
status := CkJsonObject__stringOf(jResp,'status');
organization := CkJsonObject__stringOf(jResp,'organization');
permission := CkJsonObject__stringOf(jResp,'permission');
groupId := CkJsonObject__stringOf(jResp,'group.id');
groupName := CkJsonObject__stringOf(jResp,'group.name');
createdAt := CkJsonObject__stringOf(jResp,'createdAt');
updatedAt := CkJsonObject__stringOf(jResp,'updatedAt');
deleted := CkJsonObject_BoolOf(jResp,'deleted');
deletedAt := CkJsonObject__stringOf(jResp,'deletedAt');
inweboUserRequest := CkJsonObject__stringOf(jResp,'inweboUserRequest');
samlNameId := CkJsonObject__stringOf(jResp,'samlNameId');
defaultSignImage := CkJsonObject__stringOf(jResp,'defaultSignImage');
notificationsProcedure := CkJsonObject_BoolOf(jResp,'notifications.procedure');
fastSign := CkJsonObject_BoolOf(jResp,'fastSign');
fullName := CkJsonObject__stringOf(jResp,'fullName');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'workspaces');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    id := CkJsonObject__stringOf(jResp,'workspaces[i].id');
    name := CkJsonObject__stringOf(jResp,'workspaces[i].name');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'group.permissions');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'group.permissions[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'config');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

end;