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
(PureBasic) 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
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; 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.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"name","My first procedure with emails") CkJsonObject::ckUpdateString(json,"description","Powerful! Here is the description of my first procedure with emails") CkJsonObject::ckUpdateString(json,"members[0].firstname","John") CkJsonObject::ckUpdateString(json,"members[0].lastname","Doe") CkJsonObject::ckUpdateString(json,"members[0].email","john.doe@yousign.fr") CkJsonObject::ckUpdateString(json,"members[0].phone","+33612345678") ; Use the actual file ID here... CkJsonObject::ckUpdateString(json,"members[0].fileObjects[0].file","/files/23686fbe-3ae1-4de9-9e01-58bbf29b2b18") CkJsonObject::ckUpdateInt(json,"members[0].fileObjects[0].page",2) CkJsonObject::ckUpdateString(json,"members[0].fileObjects[0].position","230,499,464,589") CkJsonObject::ckUpdateString(json,"members[0].fileObjects[0].mention","Read and approved") CkJsonObject::ckUpdateString(json,"members[0].fileObjects[0].mention2","Signed by John Doe") CkJsonObject::ckUpdateString(json,"config.email." + Chr(34) + "member.started" + Chr(34) + "[0].subject","Hey! You are invited to sign!") CkJsonObject::ckUpdateString(json,"config.email." + Chr(34) + "member.started" + Chr(34) + "[0].message","Hello <tag data-tag-type=" + Chr(34) + "string" + Chr(34) + " data-tag-name=" + Chr(34) + "recipient.firstname" + Chr(34) + "></tag> <tag data-tag-type=" + Chr(34) + "string" + Chr(34) + " data-tag-name=" + Chr(34) + "recipient.lastname" + Chr(34) + "></tag>, <br><br> You have ben invited to sign a document, please click on the following button to read it: <tag data-tag-type=" + Chr(34) + "button" + Chr(34) + " data-tag-name=" + Chr(34) + "url" + Chr(34) + " data-tag-title=" + Chr(34) + "Access to documents" + Chr(34) + ">Access to documents</tag>") CkJsonObject::ckUpdateString(json,"config.email." + Chr(34) + "member.started" + Chr(34) + "[0].to[0]","@member") CkJsonObject::ckUpdateString(json,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[0].subject","John, created a procedure your API have.") CkJsonObject::ckUpdateString(json,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[0].message","The content of this email is totally awesome.") CkJsonObject::ckUpdateString(json,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[0].to[0]","@creator") CkJsonObject::ckUpdateString(json,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[0].to[1]","@members") CkJsonObject::ckUpdateString(json,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[0].to[2]","billing@yousign.fr") ; Adds the "Authorization: Bearer YOUR_API_KEY" header. CkHttp::setCkAuthToken(http, "YOUR_API_KEY") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") resp.i = CkHttp::ckPostJson3(http,"https://staging-api.yousign.com/procedures","application/json",json) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(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 subject.s message.s j.i count_j.i strVal.s user.s v_type.s firstname.s lastname.s email.s phone.s position.i comment.s operationLevel.s operationModeSmsConfig.s fileId.s fileName.s fileType.s fileContentType.s fileDescription.s fileCreatedAt.s fileUpdatedAt.s fileSha256.s fileWorkspace.s fileCreator.s fileProtected.i filePosition.i fileParent.s page.i position_str.s fieldName.s mention.s mention2.s reason.s k.i count_k.i contentType.s sha256.s v_protected.i id.s = CkJsonObject::ckStringOf(jResp,"id") name.s = CkJsonObject::ckStringOf(jResp,"name") description.s = CkJsonObject::ckStringOf(jResp,"description") createdAt.s = CkJsonObject::ckStringOf(jResp,"createdAt") updatedAt.s = CkJsonObject::ckStringOf(jResp,"updatedAt") finishedAt.s = CkJsonObject::ckStringOf(jResp,"finishedAt") expiresAt.s = CkJsonObject::ckStringOf(jResp,"expiresAt") status.s = CkJsonObject::ckStringOf(jResp,"status") creator.s = CkJsonObject::ckStringOf(jResp,"creator") creatorFirstName.s = CkJsonObject::ckStringOf(jResp,"creatorFirstName") creatorLastName.s = CkJsonObject::ckStringOf(jResp,"creatorLastName") workspace.s = CkJsonObject::ckStringOf(jResp,"workspace") template.i = CkJsonObject::ckBoolOf(jResp,"template") ordered.i = CkJsonObject::ckBoolOf(jResp,"ordered") parent.s = CkJsonObject::ckStringOf(jResp,"parent") relatedFilesEnable.i = CkJsonObject::ckBoolOf(jResp,"relatedFilesEnable") archive.i = CkJsonObject::ckBoolOf(jResp,"archive") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"metadata") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"config.email." + Chr(34) + "procedure.started" + Chr(34)) While i < count_i CkJsonObject::setCkI(jResp, i) subject = CkJsonObject::ckStringOf(jResp,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[i].subject") message = CkJsonObject::ckStringOf(jResp,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[i].message") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[i].to") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"config.email." + Chr(34) + "procedure.started" + Chr(34) + "[i].to[j]") j = j + 1 Wend i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"config.email." + Chr(34) + "member.started" + Chr(34)) While i < count_i CkJsonObject::setCkI(jResp, i) subject = CkJsonObject::ckStringOf(jResp,"config.email." + Chr(34) + "member.started" + Chr(34) + "[i].subject") message = CkJsonObject::ckStringOf(jResp,"config.email." + Chr(34) + "member.started" + Chr(34) + "[i].message") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"config.email." + Chr(34) + "member.started" + Chr(34) + "[i].to") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"config.email." + Chr(34) + "member.started" + Chr(34) + "[i].to[j]") j = j + 1 Wend i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"members") While i < count_i CkJsonObject::setCkI(jResp, i) id = CkJsonObject::ckStringOf(jResp,"members[i].id") user = CkJsonObject::ckStringOf(jResp,"members[i].user") v_type = CkJsonObject::ckStringOf(jResp,"members[i].type") firstname = CkJsonObject::ckStringOf(jResp,"members[i].firstname") lastname = CkJsonObject::ckStringOf(jResp,"members[i].lastname") email = CkJsonObject::ckStringOf(jResp,"members[i].email") phone = CkJsonObject::ckStringOf(jResp,"members[i].phone") position = CkJsonObject::ckIntOf(jResp,"members[i].position") createdAt = CkJsonObject::ckStringOf(jResp,"members[i].createdAt") updatedAt = CkJsonObject::ckStringOf(jResp,"members[i].updatedAt") finishedAt = CkJsonObject::ckStringOf(jResp,"members[i].finishedAt") status = CkJsonObject::ckStringOf(jResp,"members[i].status") comment = CkJsonObject::ckStringOf(jResp,"members[i].comment") operationLevel = CkJsonObject::ckStringOf(jResp,"members[i].operationLevel") operationModeSmsConfig = CkJsonObject::ckStringOf(jResp,"members[i].operationModeSmsConfig") parent = CkJsonObject::ckStringOf(jResp,"members[i].parent") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"members[i].fileObjects") While j < count_j CkJsonObject::setCkJ(jResp, j) id = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].id") fileId = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.id") fileName = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.name") fileType = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.type") fileContentType = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.contentType") fileDescription = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.description") fileCreatedAt = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.createdAt") fileUpdatedAt = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.updatedAt") fileSha256 = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.sha256") fileWorkspace = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.workspace") fileCreator = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.creator") fileProtected = CkJsonObject::ckBoolOf(jResp,"members[i].fileObjects[j].file.protected") filePosition = CkJsonObject::ckIntOf(jResp,"members[i].fileObjects[j].file.position") fileParent = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].file.parent") page = CkJsonObject::ckIntOf(jResp,"members[i].fileObjects[j].page") position_str = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].position") fieldName = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].fieldName") mention = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].mention") mention2 = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].mention2") createdAt = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].createdAt") updatedAt = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].updatedAt") parent = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].parent") reason = CkJsonObject::ckStringOf(jResp,"members[i].fileObjects[j].reason") k = 0 count_k = CkJsonObject::ckSizeOfArray(jResp,"members[i].fileObjects[j].file.metadata") While k < count_k CkJsonObject::setCkK(jResp, k) k = k + 1 Wend j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"members[i].notificationsEmail") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"members[i].operationCustomModes") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"members[i].operationCustomModes[j]") j = j + 1 Wend i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"subscribers") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"files") While i < count_i CkJsonObject::setCkI(jResp, i) id = CkJsonObject::ckStringOf(jResp,"files[i].id") name = CkJsonObject::ckStringOf(jResp,"files[i].name") v_type = CkJsonObject::ckStringOf(jResp,"files[i].type") contentType = CkJsonObject::ckStringOf(jResp,"files[i].contentType") description = CkJsonObject::ckStringOf(jResp,"files[i].description") createdAt = CkJsonObject::ckStringOf(jResp,"files[i].createdAt") updatedAt = CkJsonObject::ckStringOf(jResp,"files[i].updatedAt") sha256 = CkJsonObject::ckStringOf(jResp,"files[i].sha256") workspace = CkJsonObject::ckStringOf(jResp,"files[i].workspace") creator = CkJsonObject::ckStringOf(jResp,"files[i].creator") v_protected = CkJsonObject::ckBoolOf(jResp,"files[i].protected") position = CkJsonObject::ckIntOf(jResp,"files[i].position") parent = CkJsonObject::ckStringOf(jResp,"files[i].parent") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"files[i].metadata") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"archiveMetadata") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"fields") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"permissions") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.