Unicode C++
Unicode C++
Yousign - Setup email notifications
See more Yousign Examples
Demonstrates 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.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
// 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"
// ]
// }
// ]
// }
// }
// }
CkJsonObjectW json;
json.UpdateString(L"name",L"My first procedure with emails");
json.UpdateString(L"description",L"Powerful! Here is the description of my first procedure with emails");
json.UpdateString(L"members[0].firstname",L"John");
json.UpdateString(L"members[0].lastname",L"Doe");
json.UpdateString(L"members[0].email",L"john.doe@yousign.fr");
json.UpdateString(L"members[0].phone",L"+33612345678");
// Use the actual file ID here...
json.UpdateString(L"members[0].fileObjects[0].file",L"/files/23686fbe-3ae1-4de9-9e01-58bbf29b2b18");
json.UpdateInt(L"members[0].fileObjects[0].page",2);
json.UpdateString(L"members[0].fileObjects[0].position",L"230,499,464,589");
json.UpdateString(L"members[0].fileObjects[0].mention",L"Read and approved");
json.UpdateString(L"members[0].fileObjects[0].mention2",L"Signed by John Doe");
json.UpdateString(L"config.email.\"member.started\"[0].subject",L"Hey! You are invited to sign!");
json.UpdateString(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>");
json.UpdateString(L"config.email.\"member.started\"[0].to[0]",L"@member");
json.UpdateString(L"config.email.\"procedure.started\"[0].subject",L"John, created a procedure your API have.");
json.UpdateString(L"config.email.\"procedure.started\"[0].message",L"The content of this email is totally awesome.");
json.UpdateString(L"config.email.\"procedure.started\"[0].to[0]",L"@creator");
json.UpdateString(L"config.email.\"procedure.started\"[0].to[1]",L"@members");
json.UpdateString(L"config.email.\"procedure.started\"[0].to[2]",L"billing@yousign.fr");
// Adds the "Authorization: Bearer YOUR_API_KEY" header.
http.put_AuthToken(L"YOUR_API_KEY");
CkHttpResponseW resp;
success = http.HttpJson(L"POST",L"https://staging-api.yousign.com/procedures",json,L"application/json",resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp.GetBodySb(sbResponseBody);
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",jResp.emit());
int respStatusCode = resp.get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp.header());
wprintf(L"Failed.\n");
return;
}
// 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.
const wchar_t *subject = 0;
const wchar_t *message = 0;
int j;
int count_j;
const wchar_t *strVal = 0;
const wchar_t *user = 0;
const wchar_t *v_type = 0;
const wchar_t *firstname = 0;
const wchar_t *lastname = 0;
const wchar_t *email = 0;
const wchar_t *phone = 0;
int position;
const wchar_t *comment = 0;
const wchar_t *operationLevel = 0;
const wchar_t *operationModeSmsConfig = 0;
const wchar_t *fileId = 0;
const wchar_t *fileName = 0;
const wchar_t *fileType = 0;
const wchar_t *fileContentType = 0;
const wchar_t *fileDescription = 0;
const wchar_t *fileCreatedAt = 0;
const wchar_t *fileUpdatedAt = 0;
const wchar_t *fileSha256 = 0;
const wchar_t *fileWorkspace = 0;
const wchar_t *fileCreator = 0;
bool fileProtected;
int filePosition;
const wchar_t *fileParent = 0;
int page;
const wchar_t *position_str = 0;
const wchar_t *fieldName = 0;
const wchar_t *mention = 0;
const wchar_t *mention2 = 0;
const wchar_t *reason = 0;
int k;
int count_k;
const wchar_t *contentType = 0;
const wchar_t *sha256 = 0;
bool v_protected;
const wchar_t *id = jResp.stringOf(L"id");
const wchar_t *name = jResp.stringOf(L"name");
const wchar_t *description = jResp.stringOf(L"description");
const wchar_t *createdAt = jResp.stringOf(L"createdAt");
const wchar_t *updatedAt = jResp.stringOf(L"updatedAt");
const wchar_t *finishedAt = jResp.stringOf(L"finishedAt");
const wchar_t *expiresAt = jResp.stringOf(L"expiresAt");
const wchar_t *status = jResp.stringOf(L"status");
const wchar_t *creator = jResp.stringOf(L"creator");
const wchar_t *creatorFirstName = jResp.stringOf(L"creatorFirstName");
const wchar_t *creatorLastName = jResp.stringOf(L"creatorLastName");
const wchar_t *workspace = jResp.stringOf(L"workspace");
bool template = jResp.BoolOf(L"template");
bool ordered = jResp.BoolOf(L"ordered");
const wchar_t *parent = jResp.stringOf(L"parent");
bool relatedFilesEnable = jResp.BoolOf(L"relatedFilesEnable");
bool archive = jResp.BoolOf(L"archive");
int i = 0;
int count_i = jResp.SizeOfArray(L"metadata");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"config.email.\"procedure.started\"");
while (i < count_i) {
jResp.put_I(i);
subject = jResp.stringOf(L"config.email.\"procedure.started\"[i].subject");
message = jResp.stringOf(L"config.email.\"procedure.started\"[i].message");
j = 0;
count_j = jResp.SizeOfArray(L"config.email.\"procedure.started\"[i].to");
while (j < count_j) {
jResp.put_J(j);
strVal = jResp.stringOf(L"config.email.\"procedure.started\"[i].to[j]");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"config.email.\"member.started\"");
while (i < count_i) {
jResp.put_I(i);
subject = jResp.stringOf(L"config.email.\"member.started\"[i].subject");
message = jResp.stringOf(L"config.email.\"member.started\"[i].message");
j = 0;
count_j = jResp.SizeOfArray(L"config.email.\"member.started\"[i].to");
while (j < count_j) {
jResp.put_J(j);
strVal = jResp.stringOf(L"config.email.\"member.started\"[i].to[j]");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"members");
while (i < count_i) {
jResp.put_I(i);
id = jResp.stringOf(L"members[i].id");
user = jResp.stringOf(L"members[i].user");
v_type = jResp.stringOf(L"members[i].type");
firstname = jResp.stringOf(L"members[i].firstname");
lastname = jResp.stringOf(L"members[i].lastname");
email = jResp.stringOf(L"members[i].email");
phone = jResp.stringOf(L"members[i].phone");
position = jResp.IntOf(L"members[i].position");
createdAt = jResp.stringOf(L"members[i].createdAt");
updatedAt = jResp.stringOf(L"members[i].updatedAt");
finishedAt = jResp.stringOf(L"members[i].finishedAt");
status = jResp.stringOf(L"members[i].status");
comment = jResp.stringOf(L"members[i].comment");
operationLevel = jResp.stringOf(L"members[i].operationLevel");
operationModeSmsConfig = jResp.stringOf(L"members[i].operationModeSmsConfig");
parent = jResp.stringOf(L"members[i].parent");
j = 0;
count_j = jResp.SizeOfArray(L"members[i].fileObjects");
while (j < count_j) {
jResp.put_J(j);
id = jResp.stringOf(L"members[i].fileObjects[j].id");
fileId = jResp.stringOf(L"members[i].fileObjects[j].file.id");
fileName = jResp.stringOf(L"members[i].fileObjects[j].file.name");
fileType = jResp.stringOf(L"members[i].fileObjects[j].file.type");
fileContentType = jResp.stringOf(L"members[i].fileObjects[j].file.contentType");
fileDescription = jResp.stringOf(L"members[i].fileObjects[j].file.description");
fileCreatedAt = jResp.stringOf(L"members[i].fileObjects[j].file.createdAt");
fileUpdatedAt = jResp.stringOf(L"members[i].fileObjects[j].file.updatedAt");
fileSha256 = jResp.stringOf(L"members[i].fileObjects[j].file.sha256");
fileWorkspace = jResp.stringOf(L"members[i].fileObjects[j].file.workspace");
fileCreator = jResp.stringOf(L"members[i].fileObjects[j].file.creator");
fileProtected = jResp.BoolOf(L"members[i].fileObjects[j].file.protected");
filePosition = jResp.IntOf(L"members[i].fileObjects[j].file.position");
fileParent = jResp.stringOf(L"members[i].fileObjects[j].file.parent");
page = jResp.IntOf(L"members[i].fileObjects[j].page");
position_str = jResp.stringOf(L"members[i].fileObjects[j].position");
fieldName = jResp.stringOf(L"members[i].fileObjects[j].fieldName");
mention = jResp.stringOf(L"members[i].fileObjects[j].mention");
mention2 = jResp.stringOf(L"members[i].fileObjects[j].mention2");
createdAt = jResp.stringOf(L"members[i].fileObjects[j].createdAt");
updatedAt = jResp.stringOf(L"members[i].fileObjects[j].updatedAt");
parent = jResp.stringOf(L"members[i].fileObjects[j].parent");
reason = jResp.stringOf(L"members[i].fileObjects[j].reason");
k = 0;
count_k = jResp.SizeOfArray(L"members[i].fileObjects[j].file.metadata");
while (k < count_k) {
jResp.put_K(k);
k = k + 1;
}
j = j + 1;
}
j = 0;
count_j = jResp.SizeOfArray(L"members[i].notificationsEmail");
while (j < count_j) {
jResp.put_J(j);
j = j + 1;
}
j = 0;
count_j = jResp.SizeOfArray(L"members[i].operationCustomModes");
while (j < count_j) {
jResp.put_J(j);
strVal = jResp.stringOf(L"members[i].operationCustomModes[j]");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"subscribers");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"files");
while (i < count_i) {
jResp.put_I(i);
id = jResp.stringOf(L"files[i].id");
name = jResp.stringOf(L"files[i].name");
v_type = jResp.stringOf(L"files[i].type");
contentType = jResp.stringOf(L"files[i].contentType");
description = jResp.stringOf(L"files[i].description");
createdAt = jResp.stringOf(L"files[i].createdAt");
updatedAt = jResp.stringOf(L"files[i].updatedAt");
sha256 = jResp.stringOf(L"files[i].sha256");
workspace = jResp.stringOf(L"files[i].workspace");
creator = jResp.stringOf(L"files[i].creator");
v_protected = jResp.BoolOf(L"files[i].protected");
position = jResp.IntOf(L"files[i].position");
parent = jResp.stringOf(L"files[i].parent");
j = 0;
count_j = jResp.SizeOfArray(L"files[i].metadata");
while (j < count_j) {
jResp.put_J(j);
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"archiveMetadata");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"fields");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"permissions");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
}