Lua
Lua
Yousign Create Procedure after Uploading the PDF
See more Yousign Examples
Demonstrates the 2nd step of Yousign procedure creation. This is the call to create the procedure after previously uploading the PDF file.Chilkat Lua Downloads
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",
-- "description": "Awesome! Here is the description of my first procedure",
-- "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"
-- }
-- ]
-- }
-- ]
-- }'
-- 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",
-- "description": "Awesome! Here is the description of my first procedure",
-- "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"
-- }
-- ]
-- }
-- ]
-- }
local json = chilkat.JsonObject.new()
json:update_string("name", "My first procedure")
json:update_string("description", "Awesome! Here is the description of my first procedure")
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")
json:update_string("members[0].fileObjects[0].file", "/files/6c123a8d-e5cf-4534-8da0-81886376ba2c")
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")
-- 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",
-- "description": "Awesome! Here is the description of my first procedure",
-- "createdAt": "2018-12-01T11:49:11+01:00",
-- "updatedAt": "2018-12-01T11:49:11+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": [
-- ],
-- "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-01T11:49:11+01:00",
-- "updatedAt": "2018-12-01T11:49:11+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-01T11:36:20+01:00",
-- "updatedAt": "2018-12-01T11:49:11+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-01T11:49:11+01:00",
-- "updatedAt": "2018-12-01T11:49:11+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-01T11:36:20+01:00",
-- "updatedAt": "2018-12-01T11:49:11+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 user = ""
local v_type = ""
local firstname = ""
local lastname = ""
local email = ""
local phone = ""
local position = 0
local comment = ""
local operationLevel = ""
local operationModeSmsConfig = ""
local j = 0
local count_j = 0
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 strVal = ""
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")
while i < count_i do
jResp.i = i
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