Sample code for 30+ languages & platforms
AutoIt

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

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.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"
;           ]
;         }
;       ]
;     }
;   }
; }

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

; Adds the "Authorization: Bearer YOUR_API_KEY" header.
$oHttp.AuthToken = "YOUR_API_KEY"

$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpJson("POST","https://staging-api.yousign.com/procedures",$oJson,"application/json",$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

; 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 $sMessage
Local $iJ
Local $iCount_j
Local $strVal
Local $sUser
Local $sV_type
Local $sFirstname
Local $sLastname
Local $sEmail
Local $sPhone
Local $iPosition
Local $sComment
Local $sOperationLevel
Local $sOperationModeSmsConfig
Local $sFileId
Local $sFileName
Local $sFileType
Local $sFileContentType
Local $sFileDescription
Local $sFileCreatedAt
Local $sFileUpdatedAt
Local $sFileSha256
Local $sFileWorkspace
Local $sFileCreator
Local $bFileProtected
Local $iFilePosition
Local $sFileParent
Local $iPage
Local $sPosition_str
Local $sFieldName
Local $sMention
Local $sMention2
Local $sReason
Local $iK
Local $iCount_k
Local $sContentType
Local $sha256
Local $bV_protected

Local $sId = $oJResp.StringOf("id")
Local $sName = $oJResp.StringOf("name")
Local $sDescription = $oJResp.StringOf("description")
Local $sCreatedAt = $oJResp.StringOf("createdAt")
Local $sUpdatedAt = $oJResp.StringOf("updatedAt")
Local $sFinishedAt = $oJResp.StringOf("finishedAt")
Local $sExpiresAt = $oJResp.StringOf("expiresAt")
Local $status = $oJResp.StringOf("status")
Local $sCreator = $oJResp.StringOf("creator")
Local $sCreatorFirstName = $oJResp.StringOf("creatorFirstName")
Local $sCreatorLastName = $oJResp.StringOf("creatorLastName")
Local $sWorkspace = $oJResp.StringOf("workspace")
Local $bTemplate = $oJResp.BoolOf("template")
Local $bOrdered = $oJResp.BoolOf("ordered")
Local $sParent = $oJResp.StringOf("parent")
Local $bRelatedFilesEnable = $oJResp.BoolOf("relatedFilesEnable")
Local $bArchive = $oJResp.BoolOf("archive")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("metadata")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("config.email.""procedure.started""")
While $i < $iCount_i
    $oJResp.I = $i
    $subject = $oJResp.StringOf("config.email.""procedure.started""[i].subject")
    $sMessage = $oJResp.StringOf("config.email.""procedure.started""[i].message")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("config.email.""procedure.started""[i].to")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $strVal = $oJResp.StringOf("config.email.""procedure.started""[i].to[j]")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("config.email.""member.started""")
While $i < $iCount_i
    $oJResp.I = $i
    $subject = $oJResp.StringOf("config.email.""member.started""[i].subject")
    $sMessage = $oJResp.StringOf("config.email.""member.started""[i].message")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("config.email.""member.started""[i].to")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $strVal = $oJResp.StringOf("config.email.""member.started""[i].to[j]")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("members")
While $i < $iCount_i
    $oJResp.I = $i
    $sId = $oJResp.StringOf("members[i].id")
    $sUser = $oJResp.StringOf("members[i].user")
    $sV_type = $oJResp.StringOf("members[i].type")
    $sFirstname = $oJResp.StringOf("members[i].firstname")
    $sLastname = $oJResp.StringOf("members[i].lastname")
    $sEmail = $oJResp.StringOf("members[i].email")
    $sPhone = $oJResp.StringOf("members[i].phone")
    $iPosition = $oJResp.IntOf("members[i].position")
    $sCreatedAt = $oJResp.StringOf("members[i].createdAt")
    $sUpdatedAt = $oJResp.StringOf("members[i].updatedAt")
    $sFinishedAt = $oJResp.StringOf("members[i].finishedAt")
    $status = $oJResp.StringOf("members[i].status")
    $sComment = $oJResp.StringOf("members[i].comment")
    $sOperationLevel = $oJResp.StringOf("members[i].operationLevel")
    $sOperationModeSmsConfig = $oJResp.StringOf("members[i].operationModeSmsConfig")
    $sParent = $oJResp.StringOf("members[i].parent")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("members[i].fileObjects")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sId = $oJResp.StringOf("members[i].fileObjects[j].id")
        $sFileId = $oJResp.StringOf("members[i].fileObjects[j].file.id")
        $sFileName = $oJResp.StringOf("members[i].fileObjects[j].file.name")
        $sFileType = $oJResp.StringOf("members[i].fileObjects[j].file.type")
        $sFileContentType = $oJResp.StringOf("members[i].fileObjects[j].file.contentType")
        $sFileDescription = $oJResp.StringOf("members[i].fileObjects[j].file.description")
        $sFileCreatedAt = $oJResp.StringOf("members[i].fileObjects[j].file.createdAt")
        $sFileUpdatedAt = $oJResp.StringOf("members[i].fileObjects[j].file.updatedAt")
        $sFileSha256 = $oJResp.StringOf("members[i].fileObjects[j].file.sha256")
        $sFileWorkspace = $oJResp.StringOf("members[i].fileObjects[j].file.workspace")
        $sFileCreator = $oJResp.StringOf("members[i].fileObjects[j].file.creator")
        $bFileProtected = $oJResp.BoolOf("members[i].fileObjects[j].file.protected")
        $iFilePosition = $oJResp.IntOf("members[i].fileObjects[j].file.position")
        $sFileParent = $oJResp.StringOf("members[i].fileObjects[j].file.parent")
        $iPage = $oJResp.IntOf("members[i].fileObjects[j].page")
        $sPosition_str = $oJResp.StringOf("members[i].fileObjects[j].position")
        $sFieldName = $oJResp.StringOf("members[i].fileObjects[j].fieldName")
        $sMention = $oJResp.StringOf("members[i].fileObjects[j].mention")
        $sMention2 = $oJResp.StringOf("members[i].fileObjects[j].mention2")
        $sCreatedAt = $oJResp.StringOf("members[i].fileObjects[j].createdAt")
        $sUpdatedAt = $oJResp.StringOf("members[i].fileObjects[j].updatedAt")
        $sParent = $oJResp.StringOf("members[i].fileObjects[j].parent")
        $sReason = $oJResp.StringOf("members[i].fileObjects[j].reason")
        $iK = 0
        $iCount_k = $oJResp.SizeOfArray("members[i].fileObjects[j].file.metadata")
        While $iK < $iCount_k
            $oJResp.K = $iK
            $iK = $iK + 1
        Wend
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("members[i].notificationsEmail")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("members[i].operationCustomModes")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $strVal = $oJResp.StringOf("members[i].operationCustomModes[j]")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("subscribers")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("files")
While $i < $iCount_i
    $oJResp.I = $i
    $sId = $oJResp.StringOf("files[i].id")
    $sName = $oJResp.StringOf("files[i].name")
    $sV_type = $oJResp.StringOf("files[i].type")
    $sContentType = $oJResp.StringOf("files[i].contentType")
    $sDescription = $oJResp.StringOf("files[i].description")
    $sCreatedAt = $oJResp.StringOf("files[i].createdAt")
    $sUpdatedAt = $oJResp.StringOf("files[i].updatedAt")
    $sha256 = $oJResp.StringOf("files[i].sha256")
    $sWorkspace = $oJResp.StringOf("files[i].workspace")
    $sCreator = $oJResp.StringOf("files[i].creator")
    $bV_protected = $oJResp.BoolOf("files[i].protected")
    $iPosition = $oJResp.IntOf("files[i].position")
    $sParent = $oJResp.StringOf("files[i].parent")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("files[i].metadata")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("archiveMetadata")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("fields")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("permissions")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend