Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Yousign - Setup email notificationsDemonstrates how to setup email notifications based on events. An event is triggered when a user (or our API) make an action or when a status has changed. For more information, see https://dev.yousign.com/?version=latest#96b9f5ec-8e41-4d0f-82e5-6fa91adfa4fd
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; success: Boolean; json: HCkJsonObject; resp: HCkHttpResponse; sbResponseBody: HCkStringBuilder; jResp: HCkJsonObject; respStatusCode: Integer; subject: PWideChar; message: PWideChar; j: Integer; count_j: Integer; strVal: PWideChar; user: PWideChar; v_type: PWideChar; firstname: PWideChar; lastname: PWideChar; email: PWideChar; phone: PWideChar; position: Integer; comment: PWideChar; operationLevel: PWideChar; operationModeSmsConfig: PWideChar; fileId: PWideChar; fileName: PWideChar; fileType: PWideChar; fileContentType: PWideChar; fileDescription: PWideChar; fileCreatedAt: PWideChar; fileUpdatedAt: PWideChar; fileSha256: PWideChar; fileWorkspace: PWideChar; fileCreator: PWideChar; fileProtected: Boolean; filePosition: Integer; fileParent: PWideChar; page: Integer; position_str: PWideChar; fieldName: PWideChar; mention: PWideChar; mention2: PWideChar; reason: PWideChar; k: Integer; count_k: Integer; contentType: PWideChar; sha256: PWideChar; v_protected: Boolean; id: PWideChar; name: PWideChar; description: PWideChar; createdAt: PWideChar; updatedAt: PWideChar; finishedAt: PWideChar; expiresAt: PWideChar; status: PWideChar; creator: PWideChar; creatorFirstName: PWideChar; creatorLastName: PWideChar; workspace: PWideChar; template: Boolean; ordered: Boolean; parent: PWideChar; relatedFilesEnable: Boolean; archive: Boolean; i: Integer; count_i: Integer; begin // 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 POST 'https://staging-api.yousign.com/procedures' \ // --header 'Authorization: Bearer YOUR_API_KEY' \ // --header 'Content-Type: application/json' \ // --data-raw '{ // "name": "My first procedure with emails", // "description": "Powerful! Here is the description of my first procedure with emails", // "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" // } // ] // } // ], // "config": { // "email": { // "member.started": [ // { // "subject": "Hey! You are invited to sign!", // "message": "Hello <tag data-tag-type=\"string\" data-tag-name=\"recipient.firstname\"></tag> <tag data-tag-type=\"string\" data-tag-name=\"recipient.lastname\"></tag>, <br><br> You have ben invited to sign a document, please click on the following button to read it: <tag data-tag-type=\"button\" data-tag-name=\"url\" data-tag-title=\"Access to documents\">Access to documents</tag>", // "to": ["@member"] // } // ], // "procedure.started": [ // { // "subject": "John, created a procedure your API have.", // "message": "The content of this email is totally awesome.", // "to": ["@creator", "@members", "billing@yousign.fr"] // } // ] // } // } // }' // 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 with emails", // "description": "Powerful! Here is the description of my first procedure with emails", // "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" // } // ] // } // ], // "config": { // "email": { // "member.started": [ // { // "subject": "Hey! You are invited to sign!", // "message": "Hello <tag data-tag-type=", // " data-tag-name=": <tag, // "button": [ // "@member" // ] // } // ], // "procedure.started": [ // { // "subject": "John, created a procedure your API have.", // "message": "The content of this email is totally awesome.", // "to": [ // "@creator", // "@members", // "billing@yousign.fr" // ] // } // ] // } // } // } json := CkJsonObject_Create(); CkJsonObject_UpdateString(json,'name','My first procedure with emails'); CkJsonObject_UpdateString(json,'description','Powerful! Here is the description of my first procedure with emails'); CkJsonObject_UpdateString(json,'members[0].firstname','John'); CkJsonObject_UpdateString(json,'members[0].lastname','Doe'); CkJsonObject_UpdateString(json,'members[0].email','john.doe@yousign.fr'); CkJsonObject_UpdateString(json,'members[0].phone','+33612345678'); // Use the actual file ID here... CkJsonObject_UpdateString(json,'members[0].fileObjects[0].file','/files/23686fbe-3ae1-4de9-9e01-58bbf29b2b18'); CkJsonObject_UpdateInt(json,'members[0].fileObjects[0].page',2); CkJsonObject_UpdateString(json,'members[0].fileObjects[0].position','230,499,464,589'); CkJsonObject_UpdateString(json,'members[0].fileObjects[0].mention','Read and approved'); CkJsonObject_UpdateString(json,'members[0].fileObjects[0].mention2','Signed by John Doe'); CkJsonObject_UpdateString(json,'config.email."member.started"[0].subject','Hey! You are invited to sign!'); CkJsonObject_UpdateString(json,'config.email."member.started"[0].message','Hello <tag data-tag-type="string" data-tag-name="recipient.firstname"></tag> <tag data-tag-type="string" data-tag-name="recipient.lastname"></tag>, <br><br> You have ben invited to sign a document, please click on the following button to read it: <tag data-tag-type="button" data-tag-name="url" data-tag-title="Access to documents">Access to documents</tag>'); CkJsonObject_UpdateString(json,'config.email."member.started"[0].to[0]','@member'); CkJsonObject_UpdateString(json,'config.email."procedure.started"[0].subject','John, created a procedure your API have.'); CkJsonObject_UpdateString(json,'config.email."procedure.started"[0].message','The content of this email is totally awesome.'); CkJsonObject_UpdateString(json,'config.email."procedure.started"[0].to[0]','@creator'); CkJsonObject_UpdateString(json,'config.email."procedure.started"[0].to[1]','@members'); CkJsonObject_UpdateString(json,'config.email."procedure.started"[0].to[2]','billing@yousign.fr'); // Adds the "Authorization: Bearer YOUR_API_KEY" header. CkHttp_putAuthToken(http,'YOUR_API_KEY'); CkHttp_SetRequestHeader(http,'Content-Type','application/json'); resp := CkHttp_PostJson3(http,'https://staging-api.yousign.com/procedures','application/json',json); if (CkHttp_getLastMethodSuccess(http) = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; sbResponseBody := CkStringBuilder_Create(); CkHttpResponse_GetBodySb(resp,sbResponseBody); jResp := CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonObject__emit(jResp)); respStatusCode := CkHttpResponse_getStatusCode(resp); Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkHttpResponse__header(resp)); Memo1.Lines.Add('Failed.'); CkHttpResponse_Dispose(resp); Exit; end; CkHttpResponse_Dispose(resp); // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "id": "/procedures/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", // "name": "My first procedure with emails", // "description": "Powerful! Here is the description of my first procedure with emails", // "createdAt": "2018-12-05T06:53:34+01:00", // "updatedAt": "2018-12-05T06:53:34+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": { // "email": { // "procedure.started": [ // { // "subject": "John, created a procedure your API have.", // "message": "The content of this email is totally awesome.", // "to": [ // "@creator", // "@members", // "billing@yousign.fr" // ] // } // ], // "member.started": [ // { // "subject": "Hey! You are invited to sign!", // "message": "Hello <tag data-tag-type=\"string\" data-tag-name=\"recipient.firstname\"></tag> <tag data-tag-type=\"string\" data-tag-name=\"recipient.lastname\"></tag>, <br><br> You have ben invited to sign a document, please click on the following button to read it: <tag data-tag-type=\"button\" data-tag-name=\"url\" data-tag-title=\"Access to documents\">Access to documents</tag>", // "to": [ // "@member" // ] // } // ] // } // }, // "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-05T06:53:34+01:00", // "updatedAt": "2018-12-05T06:53:34+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-05T06:52:54+01:00", // "updatedAt": "2018-12-05T06:53:34+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-05T06:53:34+01:00", // "updatedAt": "2018-12-05T06:53:34+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-05T06:52:54+01:00", // "updatedAt": "2018-12-05T06:53:34+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 := CkJsonObject__stringOf(jResp,'id'); name := CkJsonObject__stringOf(jResp,'name'); description := CkJsonObject__stringOf(jResp,'description'); createdAt := CkJsonObject__stringOf(jResp,'createdAt'); updatedAt := CkJsonObject__stringOf(jResp,'updatedAt'); finishedAt := CkJsonObject__stringOf(jResp,'finishedAt'); expiresAt := CkJsonObject__stringOf(jResp,'expiresAt'); status := CkJsonObject__stringOf(jResp,'status'); creator := CkJsonObject__stringOf(jResp,'creator'); creatorFirstName := CkJsonObject__stringOf(jResp,'creatorFirstName'); creatorLastName := CkJsonObject__stringOf(jResp,'creatorLastName'); workspace := CkJsonObject__stringOf(jResp,'workspace'); template := CkJsonObject_BoolOf(jResp,'template'); ordered := CkJsonObject_BoolOf(jResp,'ordered'); parent := CkJsonObject__stringOf(jResp,'parent'); relatedFilesEnable := CkJsonObject_BoolOf(jResp,'relatedFilesEnable'); archive := CkJsonObject_BoolOf(jResp,'archive'); i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'metadata'); while i < count_i do begin CkJsonObject_putI(jResp,i); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'config.email."procedure.started"'); while i < count_i do begin CkJsonObject_putI(jResp,i); subject := CkJsonObject__stringOf(jResp,'config.email."procedure.started"[i].subject'); message := CkJsonObject__stringOf(jResp,'config.email."procedure.started"[i].message'); j := 0; count_j := CkJsonObject_SizeOfArray(jResp,'config.email."procedure.started"[i].to'); while j < count_j do begin CkJsonObject_putJ(jResp,j); strVal := CkJsonObject__stringOf(jResp,'config.email."procedure.started"[i].to[j]'); j := j + 1; end; i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'config.email."member.started"'); while i < count_i do begin CkJsonObject_putI(jResp,i); subject := CkJsonObject__stringOf(jResp,'config.email."member.started"[i].subject'); message := CkJsonObject__stringOf(jResp,'config.email."member.started"[i].message'); j := 0; count_j := CkJsonObject_SizeOfArray(jResp,'config.email."member.started"[i].to'); while j < count_j do begin CkJsonObject_putJ(jResp,j); strVal := CkJsonObject__stringOf(jResp,'config.email."member.started"[i].to[j]'); j := j + 1; end; i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'members'); while i < count_i do begin CkJsonObject_putI(jResp,i); id := CkJsonObject__stringOf(jResp,'members[i].id'); user := CkJsonObject__stringOf(jResp,'members[i].user'); v_type := CkJsonObject__stringOf(jResp,'members[i].type'); firstname := CkJsonObject__stringOf(jResp,'members[i].firstname'); lastname := CkJsonObject__stringOf(jResp,'members[i].lastname'); email := CkJsonObject__stringOf(jResp,'members[i].email'); phone := CkJsonObject__stringOf(jResp,'members[i].phone'); position := CkJsonObject_IntOf(jResp,'members[i].position'); createdAt := CkJsonObject__stringOf(jResp,'members[i].createdAt'); updatedAt := CkJsonObject__stringOf(jResp,'members[i].updatedAt'); finishedAt := CkJsonObject__stringOf(jResp,'members[i].finishedAt'); status := CkJsonObject__stringOf(jResp,'members[i].status'); comment := CkJsonObject__stringOf(jResp,'members[i].comment'); operationLevel := CkJsonObject__stringOf(jResp,'members[i].operationLevel'); operationModeSmsConfig := CkJsonObject__stringOf(jResp,'members[i].operationModeSmsConfig'); parent := CkJsonObject__stringOf(jResp,'members[i].parent'); j := 0; count_j := CkJsonObject_SizeOfArray(jResp,'members[i].fileObjects'); while j < count_j do begin CkJsonObject_putJ(jResp,j); id := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].id'); fileId := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.id'); fileName := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.name'); fileType := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.type'); fileContentType := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.contentType'); fileDescription := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.description'); fileCreatedAt := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.createdAt'); fileUpdatedAt := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.updatedAt'); fileSha256 := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.sha256'); fileWorkspace := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.workspace'); fileCreator := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.creator'); fileProtected := CkJsonObject_BoolOf(jResp,'members[i].fileObjects[j].file.protected'); filePosition := CkJsonObject_IntOf(jResp,'members[i].fileObjects[j].file.position'); fileParent := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].file.parent'); page := CkJsonObject_IntOf(jResp,'members[i].fileObjects[j].page'); position_str := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].position'); fieldName := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].fieldName'); mention := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].mention'); mention2 := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].mention2'); createdAt := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].createdAt'); updatedAt := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].updatedAt'); parent := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].parent'); reason := CkJsonObject__stringOf(jResp,'members[i].fileObjects[j].reason'); k := 0; count_k := CkJsonObject_SizeOfArray(jResp,'members[i].fileObjects[j].file.metadata'); while k < count_k do begin CkJsonObject_putK(jResp,k); k := k + 1; end; j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(jResp,'members[i].notificationsEmail'); while j < count_j do begin CkJsonObject_putJ(jResp,j); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(jResp,'members[i].operationCustomModes'); while j < count_j do begin CkJsonObject_putJ(jResp,j); strVal := CkJsonObject__stringOf(jResp,'members[i].operationCustomModes[j]'); j := j + 1; end; i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'subscribers'); while i < count_i do begin CkJsonObject_putI(jResp,i); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'files'); while i < count_i do begin CkJsonObject_putI(jResp,i); id := CkJsonObject__stringOf(jResp,'files[i].id'); name := CkJsonObject__stringOf(jResp,'files[i].name'); v_type := CkJsonObject__stringOf(jResp,'files[i].type'); contentType := CkJsonObject__stringOf(jResp,'files[i].contentType'); description := CkJsonObject__stringOf(jResp,'files[i].description'); createdAt := CkJsonObject__stringOf(jResp,'files[i].createdAt'); updatedAt := CkJsonObject__stringOf(jResp,'files[i].updatedAt'); sha256 := CkJsonObject__stringOf(jResp,'files[i].sha256'); workspace := CkJsonObject__stringOf(jResp,'files[i].workspace'); creator := CkJsonObject__stringOf(jResp,'files[i].creator'); v_protected := CkJsonObject_BoolOf(jResp,'files[i].protected'); position := CkJsonObject_IntOf(jResp,'files[i].position'); parent := CkJsonObject__stringOf(jResp,'files[i].parent'); j := 0; count_j := CkJsonObject_SizeOfArray(jResp,'files[i].metadata'); while j < count_j do begin CkJsonObject_putJ(jResp,j); j := j + 1; end; i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'archiveMetadata'); while i < count_i do begin CkJsonObject_putI(jResp,i); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'fields'); while i < count_i do begin CkJsonObject_putI(jResp,i); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'permissions'); while i < count_i do begin CkJsonObject_putI(jResp,i); i := i + 1; end; CkHttp_Dispose(http); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.