Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// 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"
// ]
// }
// ]
// }
// }
// }
let json = CkoJsonObject()!
json.updateString(jsonPath: "name", value: "My first procedure with emails")
json.updateString(jsonPath: "description", value: "Powerful! Here is the description of my first procedure with emails")
json.updateString(jsonPath: "members[0].firstname", value: "John")
json.updateString(jsonPath: "members[0].lastname", value: "Doe")
json.updateString(jsonPath: "members[0].email", value: "john.doe@yousign.fr")
json.updateString(jsonPath: "members[0].phone", value: "+33612345678")
// Use the actual file ID here...
json.updateString(jsonPath: "members[0].fileObjects[0].file", value: "/files/23686fbe-3ae1-4de9-9e01-58bbf29b2b18")
json.updateInt(jsonPath: "members[0].fileObjects[0].page", value: 2)
json.updateString(jsonPath: "members[0].fileObjects[0].position", value: "230,499,464,589")
json.updateString(jsonPath: "members[0].fileObjects[0].mention", value: "Read and approved")
json.updateString(jsonPath: "members[0].fileObjects[0].mention2", value: "Signed by John Doe")
json.updateString(jsonPath: "config.email.\"member.started\"[0].subject", value: "Hey! You are invited to sign!")
json.updateString(jsonPath: "config.email.\"member.started\"[0].message", value: "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(jsonPath: "config.email.\"member.started\"[0].to[0]", value: "@member")
json.updateString(jsonPath: "config.email.\"procedure.started\"[0].subject", value: "John, created a procedure your API have.")
json.updateString(jsonPath: "config.email.\"procedure.started\"[0].message", value: "The content of this email is totally awesome.")
json.updateString(jsonPath: "config.email.\"procedure.started\"[0].to[0]", value: "@creator")
json.updateString(jsonPath: "config.email.\"procedure.started\"[0].to[1]", value: "@members")
json.updateString(jsonPath: "config.email.\"procedure.started\"[0].to[2]", value: "billing@yousign.fr")
// Adds the "Authorization: Bearer YOUR_API_KEY" header.
http.authToken = "YOUR_API_KEY"
let resp = CkoHttpResponse()!
success = http.httpJson(verb: "POST", url: "https://staging-api.yousign.com/procedures", json: json, contentType: "application/json", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
let sbResponseBody = CkoStringBuilder()!
resp.getBodySb(sb: sbResponseBody)
let jResp = CkoJsonObject()!
jResp.loadSb(sb: sbResponseBody)
jResp.emitCompact = false
print("Response Body:")
print("\(jResp.emit()!)")
var respStatusCode: Int = resp.statusCode.intValue
print("Response Status Code = \(respStatusCode)")
if respStatusCode >= 400 {
print("Response Header:")
print("\(resp.header!)")
print("Failed.")
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
var subject: String?
var message: String?
var j: Int
var count_j: Int
var strVal: String?
var user: String?
var v_type: String?
var firstname: String?
var lastname: String?
var email: String?
var phone: String?
var position: Int
var comment: String?
var operationLevel: String?
var operationModeSmsConfig: String?
var fileId: String?
var fileName: String?
var fileType: String?
var fileContentType: String?
var fileDescription: String?
var fileCreatedAt: String?
var fileUpdatedAt: String?
var fileSha256: String?
var fileWorkspace: String?
var fileCreator: String?
var fileProtected: Bool
var filePosition: Int
var fileParent: String?
var page: Int
var position_str: String?
var fieldName: String?
var mention: String?
var mention2: String?
var reason: String?
var k: Int
var count_k: Int
var contentType: String?
var sha256: String?
var v_protected: Bool
var id: String? = jResp.string(of: "id")
var name: String? = jResp.string(of: "name")
var description: String? = jResp.string(of: "description")
var createdAt: String? = jResp.string(of: "createdAt")
var updatedAt: String? = jResp.string(of: "updatedAt")
var finishedAt: String? = jResp.string(of: "finishedAt")
var expiresAt: String? = jResp.string(of: "expiresAt")
var status: String? = jResp.string(of: "status")
var creator: String? = jResp.string(of: "creator")
var creatorFirstName: String? = jResp.string(of: "creatorFirstName")
var creatorLastName: String? = jResp.string(of: "creatorLastName")
var workspace: String? = jResp.string(of: "workspace")
var template: Bool = jResp.bool(of: "template")
var ordered: Bool = jResp.bool(of: "ordered")
var parent: String? = jResp.string(of: "parent")
var relatedFilesEnable: Bool = jResp.bool(of: "relatedFilesEnable")
var archive: Bool = jResp.bool(of: "archive")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "metadata").intValue
while i < count_i {
jResp.i = i
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "config.email.\"procedure.started\"").intValue
while i < count_i {
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(ofArray: "config.email.\"procedure.started\"[i].to").intValue
while j < count_j {
jResp.j = j
strVal = jResp.string(of: "config.email.\"procedure.started\"[i].to[j]")
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "config.email.\"member.started\"").intValue
while i < count_i {
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(ofArray: "config.email.\"member.started\"[i].to").intValue
while j < count_j {
jResp.j = j
strVal = jResp.string(of: "config.email.\"member.started\"[i].to[j]")
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "members").intValue
while i < count_i {
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").intValue
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(ofArray: "members[i].fileObjects").intValue
while j < count_j {
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").intValue
fileParent = jResp.string(of: "members[i].fileObjects[j].file.parent")
page = jResp.int(of: "members[i].fileObjects[j].page").intValue
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(ofArray: "members[i].fileObjects[j].file.metadata").intValue
while k < count_k {
jResp.k = k
k = k + 1
}
j = j + 1
}
j = 0
count_j = jResp.size(ofArray: "members[i].notificationsEmail").intValue
while j < count_j {
jResp.j = j
j = j + 1
}
j = 0
count_j = jResp.size(ofArray: "members[i].operationCustomModes").intValue
while j < count_j {
jResp.j = j
strVal = jResp.string(of: "members[i].operationCustomModes[j]")
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "subscribers").intValue
while i < count_i {
jResp.i = i
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "files").intValue
while i < count_i {
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").intValue
parent = jResp.string(of: "files[i].parent")
j = 0
count_j = jResp.size(ofArray: "files[i].metadata").intValue
while j < count_j {
jResp.j = j
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "archiveMetadata").intValue
while i < count_i {
jResp.i = i
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "fields").intValue
while i < count_i {
jResp.i = i
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "permissions").intValue
while i < count_i {
jResp.i = i
i = i + 1
}
}