Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Yousign Create Procedure after Uploading the PDF
See more Yousign Examples
Demonstrates the 2nd step of Yousign procedure creation. This is the call to create the procedure after previously uploading the PDF file.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.HttpResponse,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
json: TJsonObject;
resp: THttpResponse;
sbResponseBody: TStringBuilder;
jResp: TJsonObject;
respStatusCode: Integer;
user: string;
v_type: string;
firstname: string;
lastname: string;
email: string;
phone: string;
position: Integer;
comment: string;
operationLevel: string;
operationModeSmsConfig: string;
j: Integer;
count_j: Integer;
fileId: string;
fileName: string;
fileType: string;
fileContentType: string;
fileDescription: string;
fileCreatedAt: string;
fileUpdatedAt: string;
fileSha256: string;
fileWorkspace: string;
fileCreator: string;
fileProtected: Boolean;
filePosition: Integer;
fileParent: string;
page: Integer;
position_str: string;
fieldName: string;
mention: string;
mention2: string;
reason: string;
k: Integer;
count_k: Integer;
strVal: string;
contentType: string;
sha256: string;
v_protected: Boolean;
id: string;
name: string;
description: string;
createdAt: string;
updatedAt: string;
finishedAt: string;
expiresAt: string;
status: string;
creator: string;
creatorFirstName: string;
creatorLastName: string;
workspace: string;
template: Boolean;
ordered: Boolean;
parent: string;
relatedFilesEnable: Boolean;
archive: Boolean;
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 --location --request POST 'https://staging-api.yousign.com/procedures' \
// --header 'Authorization: Bearer YOUR_API_KEY' \
// --header 'Content-Type: application/json' \
// --data-raw '{
// "name": "My first procedure",
// "description": "Awesome! Here is the description of my first procedure",
// "members": [
// {
// "firstname": "John",
// "lastname": "Doe",
// "email": "john.doe@yousign.fr",
// "phone": "+33612345678",
// "fileObjects": [
// {
// "file": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "page": 2,
// "position": "230,499,464,589",
// "mention": "Read and approved",
// "mention2": "Signed by John Doe"
// }
// ]
// }
// ]
// }'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "name": "My first procedure",
// "description": "Awesome! Here is the description of my first procedure",
// "members": [
// {
// "firstname": "John",
// "lastname": "Doe",
// "email": "john.doe@yousign.fr",
// "phone": "+33612345678",
// "fileObjects": [
// {
// "file": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "page": 2,
// "position": "230,499,464,589",
// "mention": "Read and approved",
// "mention2": "Signed by John Doe"
// }
// ]
// }
// ]
// }
json := TJsonObject.Create;
json.UpdateString('name','My first procedure');
json.UpdateString('description','Awesome! Here is the description of my first procedure');
json.UpdateString('members[0].firstname','John');
json.UpdateString('members[0].lastname','Doe');
json.UpdateString('members[0].email','john.doe@yousign.fr');
json.UpdateString('members[0].phone','+33612345678');
json.UpdateString('members[0].fileObjects[0].file','/files/6c123a8d-e5cf-4534-8da0-81886376ba2c');
json.UpdateInt('members[0].fileObjects[0].page',2);
json.UpdateString('members[0].fileObjects[0].position','230,499,464,589');
json.UpdateString('members[0].fileObjects[0].mention','Read and approved');
json.UpdateString('members[0].fileObjects[0].mention2','Signed by John Doe');
// Adds the "Authorization: Bearer YOUR_API_KEY" header.
http.AuthToken := 'YOUR_API_KEY';
resp := THttpResponse.Create;
success := http.HttpJson('POST','https://staging-api.yousign.com/procedures',json,'application/json',resp);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
sbResponseBody := TStringBuilder.Create;
resp.GetBodySb(sbResponseBody);
jResp := TJsonObject.Create;
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact := False;
WriteLn('Response Body:');
WriteLn(jResp.Emit());
respStatusCode := resp.StatusCode;
WriteLn('Response Status Code = ' + respStatusCode);
if (respStatusCode >= 400) then
begin
WriteLn('Response Header:');
WriteLn(resp.Header);
WriteLn('Failed.');
Exit;
end;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": "/procedures/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "My first procedure",
// "description": "Awesome! Here is the description of my first procedure",
// "createdAt": "2018-12-01T11:49:11+01:00",
// "updatedAt": "2018-12-01T11:49:11+01:00",
// "finishedAt": null,
// "expiresAt": null,
// "status": "active",
// "creator": null,
// "creatorFirstName": null,
// "creatorLastName": null,
// "workspace": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "template": false,
// "ordered": false,
// "parent": null,
// "metadata": [
// ],
// "config": [
// ],
// "members": [
// {
// "id": "/members/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "user": null,
// "type": "signer",
// "firstname": "John",
// "lastname": "Doe",
// "email": "john.doe@yousign.fr",
// "phone": "+33612345678",
// "position": 1,
// "createdAt": "2018-12-01T11:49:11+01:00",
// "updatedAt": "2018-12-01T11:49:11+01:00",
// "finishedAt": null,
// "status": "pending",
// "fileObjects": [
// {
// "id": "/file_objects/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "file": {
// "id": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "The best name for my file.pdf",
// "type": "signable",
// "contentType": "application/pdf",
// "description": null,
// "createdAt": "2018-12-01T11:36:20+01:00",
// "updatedAt": "2018-12-01T11:49:11+01:00",
// "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2",
// "metadata": [
// ],
// "workspace": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "creator": null,
// "protected": false,
// "position": 0,
// "parent": null
// },
// "page": 2,
// "position": "230,499,464,589",
// "fieldName": null,
// "mention": "Read and approved",
// "mention2": "Signed by John Doe",
// "createdAt": "2018-12-01T11:49:11+01:00",
// "updatedAt": "2018-12-01T11:49:11+01:00",
// "parent": null,
// "reason": "Signed by Yousign"
// }
// ],
// "comment": null,
// "notificationsEmail": [
// ],
// "operationLevel": "custom",
// "operationCustomModes": [
// "sms"
// ],
// "operationModeSmsConfig": null,
// "parent": null
// }
// ],
// "subscribers": [
// ],
// "files": [
// {
// "id": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "The best name for my file.pdf",
// "type": "signable",
// "contentType": "application/pdf",
// "description": null,
// "createdAt": "2018-12-01T11:36:20+01:00",
// "updatedAt": "2018-12-01T11:49:11+01:00",
// "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2",
// "metadata": [
// ],
// "workspace": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "creator": null,
// "protected": false,
// "position": 0,
// "parent": null
// }
// ],
// "relatedFilesEnable": false,
// "archive": false,
// "archiveMetadata": [
// ],
// "fields": [
// ],
// "permissions": [
// ]
// }
// 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 := jResp.StringOf('id');
name := jResp.StringOf('name');
description := jResp.StringOf('description');
createdAt := jResp.StringOf('createdAt');
updatedAt := jResp.StringOf('updatedAt');
finishedAt := jResp.StringOf('finishedAt');
expiresAt := jResp.StringOf('expiresAt');
status := jResp.StringOf('status');
creator := jResp.StringOf('creator');
creatorFirstName := jResp.StringOf('creatorFirstName');
creatorLastName := jResp.StringOf('creatorLastName');
workspace := jResp.StringOf('workspace');
template := jResp.BoolOf('template');
ordered := jResp.BoolOf('ordered');
parent := jResp.StringOf('parent');
relatedFilesEnable := jResp.BoolOf('relatedFilesEnable');
archive := jResp.BoolOf('archive');
i := 0;
count_i := jResp.SizeOfArray('metadata');
while i < count_i do
begin
jResp.I := i;
i := i + 1;
end;
i := 0;
count_i := jResp.SizeOfArray('config');
while i < count_i do
begin
jResp.I := i;
i := i + 1;
end;
i := 0;
count_i := jResp.SizeOfArray('members');
while i < count_i do
begin
jResp.I := i;
id := jResp.StringOf('members[i].id');
user := jResp.StringOf('members[i].user');
v_type := jResp.StringOf('members[i].type');
firstname := jResp.StringOf('members[i].firstname');
lastname := jResp.StringOf('members[i].lastname');
email := jResp.StringOf('members[i].email');
phone := jResp.StringOf('members[i].phone');
position := jResp.IntOf('members[i].position');
createdAt := jResp.StringOf('members[i].createdAt');
updatedAt := jResp.StringOf('members[i].updatedAt');
finishedAt := jResp.StringOf('members[i].finishedAt');
status := jResp.StringOf('members[i].status');
comment := jResp.StringOf('members[i].comment');
operationLevel := jResp.StringOf('members[i].operationLevel');
operationModeSmsConfig := jResp.StringOf('members[i].operationModeSmsConfig');
parent := jResp.StringOf('members[i].parent');
j := 0;
count_j := jResp.SizeOfArray('members[i].fileObjects');
while j < count_j do
begin
jResp.J := j;
id := jResp.StringOf('members[i].fileObjects[j].id');
fileId := jResp.StringOf('members[i].fileObjects[j].file.id');
fileName := jResp.StringOf('members[i].fileObjects[j].file.name');
fileType := jResp.StringOf('members[i].fileObjects[j].file.type');
fileContentType := jResp.StringOf('members[i].fileObjects[j].file.contentType');
fileDescription := jResp.StringOf('members[i].fileObjects[j].file.description');
fileCreatedAt := jResp.StringOf('members[i].fileObjects[j].file.createdAt');
fileUpdatedAt := jResp.StringOf('members[i].fileObjects[j].file.updatedAt');
fileSha256 := jResp.StringOf('members[i].fileObjects[j].file.sha256');
fileWorkspace := jResp.StringOf('members[i].fileObjects[j].file.workspace');
fileCreator := jResp.StringOf('members[i].fileObjects[j].file.creator');
fileProtected := jResp.BoolOf('members[i].fileObjects[j].file.protected');
filePosition := jResp.IntOf('members[i].fileObjects[j].file.position');
fileParent := jResp.StringOf('members[i].fileObjects[j].file.parent');
page := jResp.IntOf('members[i].fileObjects[j].page');
position_str := jResp.StringOf('members[i].fileObjects[j].position');
fieldName := jResp.StringOf('members[i].fileObjects[j].fieldName');
mention := jResp.StringOf('members[i].fileObjects[j].mention');
mention2 := jResp.StringOf('members[i].fileObjects[j].mention2');
createdAt := jResp.StringOf('members[i].fileObjects[j].createdAt');
updatedAt := jResp.StringOf('members[i].fileObjects[j].updatedAt');
parent := jResp.StringOf('members[i].fileObjects[j].parent');
reason := jResp.StringOf('members[i].fileObjects[j].reason');
k := 0;
count_k := jResp.SizeOfArray('members[i].fileObjects[j].file.metadata');
while k < count_k do
begin
jResp.K := k;
k := k + 1;
end;
j := j + 1;
end;
j := 0;
count_j := jResp.SizeOfArray('members[i].notificationsEmail');
while j < count_j do
begin
jResp.J := j;
j := j + 1;
end;
j := 0;
count_j := jResp.SizeOfArray('members[i].operationCustomModes');
while j < count_j do
begin
jResp.J := j;
strVal := jResp.StringOf('members[i].operationCustomModes[j]');
j := j + 1;
end;
i := i + 1;
end;
i := 0;
count_i := jResp.SizeOfArray('subscribers');
while i < count_i do
begin
jResp.I := i;
i := i + 1;
end;
i := 0;
count_i := jResp.SizeOfArray('files');
while i < count_i do
begin
jResp.I := i;
id := jResp.StringOf('files[i].id');
name := jResp.StringOf('files[i].name');
v_type := jResp.StringOf('files[i].type');
contentType := jResp.StringOf('files[i].contentType');
description := jResp.StringOf('files[i].description');
createdAt := jResp.StringOf('files[i].createdAt');
updatedAt := jResp.StringOf('files[i].updatedAt');
sha256 := jResp.StringOf('files[i].sha256');
workspace := jResp.StringOf('files[i].workspace');
creator := jResp.StringOf('files[i].creator');
v_protected := jResp.BoolOf('files[i].protected');
position := jResp.IntOf('files[i].position');
parent := jResp.StringOf('files[i].parent');
j := 0;
count_j := jResp.SizeOfArray('files[i].metadata');
while j < count_j do
begin
jResp.J := j;
j := j + 1;
end;
i := i + 1;
end;
i := 0;
count_i := jResp.SizeOfArray('archiveMetadata');
while i < count_i do
begin
jResp.I := i;
i := i + 1;
end;
i := 0;
count_i := jResp.SizeOfArray('fields');
while i < count_i do
begin
jResp.I := i;
i := i + 1;
end;
i := 0;
count_i := jResp.SizeOfArray('permissions');
while i < count_i do
begin
jResp.I := i;
i := i + 1;
end;
http.Free;
json.Free;
resp.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.