Sample code for 30+ languages & platforms
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 C Downloads

C
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    HCkJsonObject json;
    HCkHttpResponse resp;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *subject;
    const char *message;
    int j;
    int count_j;
    const char *strVal;
    const char *user;
    const char *v_type;
    const char *firstname;
    const char *lastname;
    const char *email;
    const char *phone;
    int position;
    const char *comment;
    const char *operationLevel;
    const char *operationModeSmsConfig;
    const char *fileId;
    const char *fileName;
    const char *fileType;
    const char *fileContentType;
    const char *fileDescription;
    const char *fileCreatedAt;
    const char *fileUpdatedAt;
    const char *fileSha256;
    const char *fileWorkspace;
    const char *fileCreator;
    BOOL fileProtected;
    int filePosition;
    const char *fileParent;
    int page;
    const char *position_str;
    const char *fieldName;
    const char *mention;
    const char *mention2;
    const char *reason;
    int k;
    int count_k;
    const char *contentType;
    const char *sha256;
    BOOL v_protected;
    const char *id;
    const char *name;
    const char *description;
    const char *createdAt;
    const char *updatedAt;
    const char *finishedAt;
    const char *expiresAt;
    const char *status;
    const char *creator;
    const char *creatorFirstName;
    const char *creatorLastName;
    const char *workspace;
    BOOL template;
    BOOL ordered;
    const char *parent;
    BOOL relatedFilesEnable;
    BOOL archive;
    int i;
    int count_i;

    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 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");

    resp = CkHttpResponse_Create();
    success = CkHttp_HttpJson(http,"POST","https://staging-api.yousign.com/procedures",json,"application/json",resp);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkHttpResponse_Dispose(resp);
        return;
    }

    sbResponseBody = CkStringBuilder_Create();
    CkHttpResponse_GetBodySb(resp,sbResponseBody);
    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkHttpResponse_Dispose(resp);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        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.

    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) {
        CkJsonObject_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"config.email.\"procedure.started\"");
    while (i < count_i) {
        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) {
            CkJsonObject_putJ(jResp,j);
            strVal = CkJsonObject_stringOf(jResp,"config.email.\"procedure.started\"[i].to[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"config.email.\"member.started\"");
    while (i < count_i) {
        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) {
            CkJsonObject_putJ(jResp,j);
            strVal = CkJsonObject_stringOf(jResp,"config.email.\"member.started\"[i].to[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"members");
    while (i < count_i) {
        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) {
            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) {
                CkJsonObject_putK(jResp,k);
                k = k + 1;
            }

            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"members[i].notificationsEmail");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"members[i].operationCustomModes");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            strVal = CkJsonObject_stringOf(jResp,"members[i].operationCustomModes[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"subscribers");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"files");
    while (i < count_i) {
        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) {
            CkJsonObject_putJ(jResp,j);
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"archiveMetadata");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"fields");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"permissions");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);
    CkHttpResponse_Dispose(resp);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }