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
(Unicode C) 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
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW json; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *subject; const wchar_t *message; int j; int count_j; const wchar_t *strVal; const wchar_t *user; const wchar_t *v_type; const wchar_t *firstname; const wchar_t *lastname; const wchar_t *email; const wchar_t *phone; int position; const wchar_t *comment; const wchar_t *operationLevel; const wchar_t *operationModeSmsConfig; const wchar_t *fileId; const wchar_t *fileName; const wchar_t *fileType; const wchar_t *fileContentType; const wchar_t *fileDescription; const wchar_t *fileCreatedAt; const wchar_t *fileUpdatedAt; const wchar_t *fileSha256; const wchar_t *fileWorkspace; const wchar_t *fileCreator; BOOL fileProtected; int filePosition; const wchar_t *fileParent; int page; const wchar_t *position_str; const wchar_t *fieldName; const wchar_t *mention; const wchar_t *mention2; const wchar_t *reason; int k; int count_k; const wchar_t *contentType; const wchar_t *sha256; BOOL v_protected; const wchar_t *id; const wchar_t *name; const wchar_t *description; const wchar_t *createdAt; const wchar_t *updatedAt; const wchar_t *finishedAt; const wchar_t *expiresAt; const wchar_t *status; const wchar_t *creator; const wchar_t *creatorFirstName; const wchar_t *creatorLastName; const wchar_t *workspace; BOOL template; BOOL ordered; const wchar_t *parent; BOOL relatedFilesEnable; BOOL archive; int i; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_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 = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"name",L"My first procedure with emails"); CkJsonObjectW_UpdateString(json,L"description",L"Powerful! Here is the description of my first procedure with emails"); CkJsonObjectW_UpdateString(json,L"members[0].firstname",L"John"); CkJsonObjectW_UpdateString(json,L"members[0].lastname",L"Doe"); CkJsonObjectW_UpdateString(json,L"members[0].email",L"john.doe@yousign.fr"); CkJsonObjectW_UpdateString(json,L"members[0].phone",L"+33612345678"); // Use the actual file ID here... CkJsonObjectW_UpdateString(json,L"members[0].fileObjects[0].file",L"/files/23686fbe-3ae1-4de9-9e01-58bbf29b2b18"); CkJsonObjectW_UpdateInt(json,L"members[0].fileObjects[0].page",2); CkJsonObjectW_UpdateString(json,L"members[0].fileObjects[0].position",L"230,499,464,589"); CkJsonObjectW_UpdateString(json,L"members[0].fileObjects[0].mention",L"Read and approved"); CkJsonObjectW_UpdateString(json,L"members[0].fileObjects[0].mention2",L"Signed by John Doe"); CkJsonObjectW_UpdateString(json,L"config.email.\"member.started\"[0].subject",L"Hey! You are invited to sign!"); CkJsonObjectW_UpdateString(json,L"config.email.\"member.started\"[0].message",L"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>"); CkJsonObjectW_UpdateString(json,L"config.email.\"member.started\"[0].to[0]",L"@member"); CkJsonObjectW_UpdateString(json,L"config.email.\"procedure.started\"[0].subject",L"John, created a procedure your API have."); CkJsonObjectW_UpdateString(json,L"config.email.\"procedure.started\"[0].message",L"The content of this email is totally awesome."); CkJsonObjectW_UpdateString(json,L"config.email.\"procedure.started\"[0].to[0]",L"@creator"); CkJsonObjectW_UpdateString(json,L"config.email.\"procedure.started\"[0].to[1]",L"@members"); CkJsonObjectW_UpdateString(json,L"config.email.\"procedure.started\"[0].to[2]",L"billing@yousign.fr"); // Adds the "Authorization: Bearer YOUR_API_KEY" header. CkHttpW_putAuthToken(http,L"YOUR_API_KEY"); CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json"); resp = CkHttpW_PostJson3(http,L"https://staging-api.yousign.com/procedures",L"application/json",json); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); return; } sbResponseBody = CkStringBuilderW_Create(); CkHttpResponseW_GetBodySb(resp,sbResponseBody); jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } CkHttpResponseW_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 // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. id = CkJsonObjectW_stringOf(jResp,L"id"); name = CkJsonObjectW_stringOf(jResp,L"name"); description = CkJsonObjectW_stringOf(jResp,L"description"); createdAt = CkJsonObjectW_stringOf(jResp,L"createdAt"); updatedAt = CkJsonObjectW_stringOf(jResp,L"updatedAt"); finishedAt = CkJsonObjectW_stringOf(jResp,L"finishedAt"); expiresAt = CkJsonObjectW_stringOf(jResp,L"expiresAt"); status = CkJsonObjectW_stringOf(jResp,L"status"); creator = CkJsonObjectW_stringOf(jResp,L"creator"); creatorFirstName = CkJsonObjectW_stringOf(jResp,L"creatorFirstName"); creatorLastName = CkJsonObjectW_stringOf(jResp,L"creatorLastName"); workspace = CkJsonObjectW_stringOf(jResp,L"workspace"); template = CkJsonObjectW_BoolOf(jResp,L"template"); ordered = CkJsonObjectW_BoolOf(jResp,L"ordered"); parent = CkJsonObjectW_stringOf(jResp,L"parent"); relatedFilesEnable = CkJsonObjectW_BoolOf(jResp,L"relatedFilesEnable"); archive = CkJsonObjectW_BoolOf(jResp,L"archive"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"metadata"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"config.email.\"procedure.started\""); while (i < count_i) { CkJsonObjectW_putI(jResp,i); subject = CkJsonObjectW_stringOf(jResp,L"config.email.\"procedure.started\"[i].subject"); message = CkJsonObjectW_stringOf(jResp,L"config.email.\"procedure.started\"[i].message"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"config.email.\"procedure.started\"[i].to"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); strVal = CkJsonObjectW_stringOf(jResp,L"config.email.\"procedure.started\"[i].to[j]"); j = j + 1; } i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"config.email.\"member.started\""); while (i < count_i) { CkJsonObjectW_putI(jResp,i); subject = CkJsonObjectW_stringOf(jResp,L"config.email.\"member.started\"[i].subject"); message = CkJsonObjectW_stringOf(jResp,L"config.email.\"member.started\"[i].message"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"config.email.\"member.started\"[i].to"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); strVal = CkJsonObjectW_stringOf(jResp,L"config.email.\"member.started\"[i].to[j]"); j = j + 1; } i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"members"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); id = CkJsonObjectW_stringOf(jResp,L"members[i].id"); user = CkJsonObjectW_stringOf(jResp,L"members[i].user"); v_type = CkJsonObjectW_stringOf(jResp,L"members[i].type"); firstname = CkJsonObjectW_stringOf(jResp,L"members[i].firstname"); lastname = CkJsonObjectW_stringOf(jResp,L"members[i].lastname"); email = CkJsonObjectW_stringOf(jResp,L"members[i].email"); phone = CkJsonObjectW_stringOf(jResp,L"members[i].phone"); position = CkJsonObjectW_IntOf(jResp,L"members[i].position"); createdAt = CkJsonObjectW_stringOf(jResp,L"members[i].createdAt"); updatedAt = CkJsonObjectW_stringOf(jResp,L"members[i].updatedAt"); finishedAt = CkJsonObjectW_stringOf(jResp,L"members[i].finishedAt"); status = CkJsonObjectW_stringOf(jResp,L"members[i].status"); comment = CkJsonObjectW_stringOf(jResp,L"members[i].comment"); operationLevel = CkJsonObjectW_stringOf(jResp,L"members[i].operationLevel"); operationModeSmsConfig = CkJsonObjectW_stringOf(jResp,L"members[i].operationModeSmsConfig"); parent = CkJsonObjectW_stringOf(jResp,L"members[i].parent"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"members[i].fileObjects"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); id = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].id"); fileId = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.id"); fileName = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.name"); fileType = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.type"); fileContentType = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.contentType"); fileDescription = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.description"); fileCreatedAt = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.createdAt"); fileUpdatedAt = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.updatedAt"); fileSha256 = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.sha256"); fileWorkspace = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.workspace"); fileCreator = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.creator"); fileProtected = CkJsonObjectW_BoolOf(jResp,L"members[i].fileObjects[j].file.protected"); filePosition = CkJsonObjectW_IntOf(jResp,L"members[i].fileObjects[j].file.position"); fileParent = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].file.parent"); page = CkJsonObjectW_IntOf(jResp,L"members[i].fileObjects[j].page"); position_str = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].position"); fieldName = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].fieldName"); mention = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].mention"); mention2 = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].mention2"); createdAt = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].createdAt"); updatedAt = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].updatedAt"); parent = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].parent"); reason = CkJsonObjectW_stringOf(jResp,L"members[i].fileObjects[j].reason"); k = 0; count_k = CkJsonObjectW_SizeOfArray(jResp,L"members[i].fileObjects[j].file.metadata"); while (k < count_k) { CkJsonObjectW_putK(jResp,k); k = k + 1; } j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"members[i].notificationsEmail"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"members[i].operationCustomModes"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); strVal = CkJsonObjectW_stringOf(jResp,L"members[i].operationCustomModes[j]"); j = j + 1; } i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"subscribers"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"files"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); id = CkJsonObjectW_stringOf(jResp,L"files[i].id"); name = CkJsonObjectW_stringOf(jResp,L"files[i].name"); v_type = CkJsonObjectW_stringOf(jResp,L"files[i].type"); contentType = CkJsonObjectW_stringOf(jResp,L"files[i].contentType"); description = CkJsonObjectW_stringOf(jResp,L"files[i].description"); createdAt = CkJsonObjectW_stringOf(jResp,L"files[i].createdAt"); updatedAt = CkJsonObjectW_stringOf(jResp,L"files[i].updatedAt"); sha256 = CkJsonObjectW_stringOf(jResp,L"files[i].sha256"); workspace = CkJsonObjectW_stringOf(jResp,L"files[i].workspace"); creator = CkJsonObjectW_stringOf(jResp,L"files[i].creator"); v_protected = CkJsonObjectW_BoolOf(jResp,L"files[i].protected"); position = CkJsonObjectW_IntOf(jResp,L"files[i].position"); parent = CkJsonObjectW_stringOf(jResp,L"files[i].parent"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"files[i].metadata"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"archiveMetadata"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"fields"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"permissions"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.