Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- 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"
--           ]
--         }
--       ]
--     }
--   }
-- }

local json = chilkat.JsonObject.new()
json:update_string("name", "My first procedure with emails")
json:update_string("description", "Powerful! Here is the description of my first procedure with emails")
json:update_string("members[0].firstname", "John")
json:update_string("members[0].lastname", "Doe")
json:update_string("members[0].email", "john.doe@yousign.fr")
json:update_string("members[0].phone", "+33612345678")
-- Use the actual file ID here...
json:update_string("members[0].fileObjects[0].file", "/files/23686fbe-3ae1-4de9-9e01-58bbf29b2b18")
json:update_int("members[0].fileObjects[0].page", 2)
json:update_string("members[0].fileObjects[0].position", "230,499,464,589")
json:update_string("members[0].fileObjects[0].mention", "Read and approved")
json:update_string("members[0].fileObjects[0].mention2", "Signed by John Doe")
json:update_string("config.email.\"member.started\"[0].subject", "Hey! You are invited to sign!")
json:update_string("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>")
json:update_string("config.email.\"member.started\"[0].to[0]", "@member")
json:update_string("config.email.\"procedure.started\"[0].subject", "John, created a procedure your API have.")
json:update_string("config.email.\"procedure.started\"[0].message", "The content of this email is totally awesome.")
json:update_string("config.email.\"procedure.started\"[0].to[0]", "@creator")
json:update_string("config.email.\"procedure.started\"[0].to[1]", "@members")
json:update_string("config.email.\"procedure.started\"[0].to[2]", "billing@yousign.fr")

-- Adds the "Authorization: Bearer YOUR_API_KEY" header.
http.auth_token = "YOUR_API_KEY"

local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://staging-api.yousign.com/procedures", json, "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
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 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

local subject = ""
local message = ""
local j = 0
local count_j = 0
local strVal = ""
local user = ""
local v_type = ""
local firstname = ""
local lastname = ""
local email = ""
local phone = ""
local position = 0
local comment = ""
local operationLevel = ""
local operationModeSmsConfig = ""
local fileId = ""
local fileName = ""
local fileType = ""
local fileContentType = ""
local fileDescription = ""
local fileCreatedAt = ""
local fileUpdatedAt = ""
local fileSha256 = ""
local fileWorkspace = ""
local fileCreator = ""
local fileProtected = false
local filePosition = 0
local fileParent = ""
local page = 0
local position_str = ""
local fieldName = ""
local mention = ""
local mention2 = ""
local reason = ""
local k = 0
local count_k = 0
local contentType = ""
local sha256 = ""
local v_protected = false

local id = jResp:string_of("id")
local name = jResp:string_of("name")
local description = jResp:string_of("description")
local createdAt = jResp:string_of("createdAt")
local updatedAt = jResp:string_of("updatedAt")
local finishedAt = jResp:string_of("finishedAt")
local expiresAt = jResp:string_of("expiresAt")
local status = jResp:string_of("status")
local creator = jResp:string_of("creator")
local creatorFirstName = jResp:string_of("creatorFirstName")
local creatorLastName = jResp:string_of("creatorLastName")
local workspace = jResp:string_of("workspace")
local template = jResp:bool_of("template")
local ordered = jResp:bool_of("ordered")
local parent = jResp:string_of("parent")
local relatedFilesEnable = jResp:bool_of("relatedFilesEnable")
local archive = jResp:bool_of("archive")
local i = 0
local count_i = jResp:size_of_array("metadata")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("config.email.\"procedure.started\"")
while i < count_i do
    jResp.i = i
    subject = jResp:string_of("config.email.\"procedure.started\"[i].subject")
    message = jResp:string_of("config.email.\"procedure.started\"[i].message")
    j = 0
    count_j = jResp:size_of_array("config.email.\"procedure.started\"[i].to")
    while j < count_j do
        jResp.j = j
        strVal = jResp:string_of("config.email.\"procedure.started\"[i].to[j]")
        j = j + 1
    end

    i = i + 1
end

i = 0
count_i = jResp:size_of_array("config.email.\"member.started\"")
while i < count_i do
    jResp.i = i
    subject = jResp:string_of("config.email.\"member.started\"[i].subject")
    message = jResp:string_of("config.email.\"member.started\"[i].message")
    j = 0
    count_j = jResp:size_of_array("config.email.\"member.started\"[i].to")
    while j < count_j do
        jResp.j = j
        strVal = jResp:string_of("config.email.\"member.started\"[i].to[j]")
        j = j + 1
    end

    i = i + 1
end

i = 0
count_i = jResp:size_of_array("members")
while i < count_i do
    jResp.i = i
    id = jResp:string_of("members[i].id")
    user = jResp:string_of("members[i].user")
    v_type = jResp:string_of("members[i].type")
    firstname = jResp:string_of("members[i].firstname")
    lastname = jResp:string_of("members[i].lastname")
    email = jResp:string_of("members[i].email")
    phone = jResp:string_of("members[i].phone")
    position = jResp:int_of("members[i].position")
    createdAt = jResp:string_of("members[i].createdAt")
    updatedAt = jResp:string_of("members[i].updatedAt")
    finishedAt = jResp:string_of("members[i].finishedAt")
    status = jResp:string_of("members[i].status")
    comment = jResp:string_of("members[i].comment")
    operationLevel = jResp:string_of("members[i].operationLevel")
    operationModeSmsConfig = jResp:string_of("members[i].operationModeSmsConfig")
    parent = jResp:string_of("members[i].parent")
    j = 0
    count_j = jResp:size_of_array("members[i].fileObjects")
    while j < count_j do
        jResp.j = j
        id = jResp:string_of("members[i].fileObjects[j].id")
        fileId = jResp:string_of("members[i].fileObjects[j].file.id")
        fileName = jResp:string_of("members[i].fileObjects[j].file.name")
        fileType = jResp:string_of("members[i].fileObjects[j].file.type")
        fileContentType = jResp:string_of("members[i].fileObjects[j].file.contentType")
        fileDescription = jResp:string_of("members[i].fileObjects[j].file.description")
        fileCreatedAt = jResp:string_of("members[i].fileObjects[j].file.createdAt")
        fileUpdatedAt = jResp:string_of("members[i].fileObjects[j].file.updatedAt")
        fileSha256 = jResp:string_of("members[i].fileObjects[j].file.sha256")
        fileWorkspace = jResp:string_of("members[i].fileObjects[j].file.workspace")
        fileCreator = jResp:string_of("members[i].fileObjects[j].file.creator")
        fileProtected = jResp:bool_of("members[i].fileObjects[j].file.protected")
        filePosition = jResp:int_of("members[i].fileObjects[j].file.position")
        fileParent = jResp:string_of("members[i].fileObjects[j].file.parent")
        page = jResp:int_of("members[i].fileObjects[j].page")
        position_str = jResp:string_of("members[i].fileObjects[j].position")
        fieldName = jResp:string_of("members[i].fileObjects[j].fieldName")
        mention = jResp:string_of("members[i].fileObjects[j].mention")
        mention2 = jResp:string_of("members[i].fileObjects[j].mention2")
        createdAt = jResp:string_of("members[i].fileObjects[j].createdAt")
        updatedAt = jResp:string_of("members[i].fileObjects[j].updatedAt")
        parent = jResp:string_of("members[i].fileObjects[j].parent")
        reason = jResp:string_of("members[i].fileObjects[j].reason")
        k = 0
        count_k = jResp:size_of_array("members[i].fileObjects[j].file.metadata")
        while k < count_k do
            jResp.k = k
            k = k + 1
        end

        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("members[i].notificationsEmail")
    while j < count_j do
        jResp.j = j
        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("members[i].operationCustomModes")
    while j < count_j do
        jResp.j = j
        strVal = jResp:string_of("members[i].operationCustomModes[j]")
        j = j + 1
    end

    i = i + 1
end

i = 0
count_i = jResp:size_of_array("subscribers")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("files")
while i < count_i do
    jResp.i = i
    id = jResp:string_of("files[i].id")
    name = jResp:string_of("files[i].name")
    v_type = jResp:string_of("files[i].type")
    contentType = jResp:string_of("files[i].contentType")
    description = jResp:string_of("files[i].description")
    createdAt = jResp:string_of("files[i].createdAt")
    updatedAt = jResp:string_of("files[i].updatedAt")
    sha256 = jResp:string_of("files[i].sha256")
    workspace = jResp:string_of("files[i].workspace")
    creator = jResp:string_of("files[i].creator")
    v_protected = jResp:bool_of("files[i].protected")
    position = jResp:int_of("files[i].position")
    parent = jResp:string_of("files[i].parent")
    j = 0
    count_j = jResp:size_of_array("files[i].metadata")
    while j < count_j do
        jResp.j = j
        j = j + 1
    end

    i = i + 1
end

i = 0
count_i = jResp:size_of_array("archiveMetadata")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("fields")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("permissions")
while i < count_i do
    jResp.i = i
    i = i + 1
end