Lua
Lua
Yousign: Making your first API call
See more Yousign Examples
Demonstrates making the simplest of calls to test your API key. This example tests using the sandbox URLs.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 GET 'https://staging-api.yousign.com/users' \
-- --header 'Authorization: Bearer YOUR_API_KEY' \
-- --header 'Content-Type: application/json'
-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code
-- Adds the "Authorization: Bearer YOUR_API_KEY" header.
http.auth_token = "YOUR_API_KEY"
http:set_request_header("Content-Type", "application/json")
local sbResponseBody = chilkat.StringBuilder.new()
local success = http:quick_get_sb("https://staging-api.yousign.com/users", sbResponseBody)
if not success then
print(http.last_error_text)
return
end
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(http.last_header)
print("Failed.")
return
end
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "id": "/users/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
-- "firstname": "John",
-- "lastname": "Doe",
-- "email": "john.doe@yousign.fr",
-- "title": "Developer",
-- "phone": "+33612345678",
-- "status": "activated",
-- "organization": "/organizations/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
-- "workspaces": [
-- {
-- "id": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
-- "name": "Acme"
-- }
-- ],
-- "permission": "ROLE_ADMIN",
-- "group": {
-- "id": "/user_groups/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
-- "name": "Administrateur",
-- "permissions": [
-- "procedure_write",
-- "procedure_template_write",
-- "procedure_create_from_template",
-- "contact",
-- "sign",
-- "organization",
-- "user",
-- "api_key",
-- "procedure_custom_field",
-- "signature_ui",
-- "certificate",
-- "archive"
-- ]
-- },
-- "createdAt": "2018-12-01T09:42:25+01:00",
-- "updatedAt": "2018-12-01T09:42:25+01:00",
-- "deleted": false,
-- "deletedAt": null,
-- "config": [
-- ],
-- "inweboUserRequest": null,
-- "samlNameId": null,
-- "defaultSignImage": null,
-- "notifications": {
-- "procedure": true
-- },
-- "fastSign": false,
-- "fullName": "John Doe"
-- }
-- 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 name = ""
local strVal = ""
local id = jResp:string_of("id")
local firstname = jResp:string_of("firstname")
local lastname = jResp:string_of("lastname")
local email = jResp:string_of("email")
local title = jResp:string_of("title")
local phone = jResp:string_of("phone")
local status = jResp:string_of("status")
local organization = jResp:string_of("organization")
local permission = jResp:string_of("permission")
local groupId = jResp:string_of("group.id")
local groupName = jResp:string_of("group.name")
local createdAt = jResp:string_of("createdAt")
local updatedAt = jResp:string_of("updatedAt")
local deleted = jResp:bool_of("deleted")
local deletedAt = jResp:string_of("deletedAt")
local inweboUserRequest = jResp:string_of("inweboUserRequest")
local samlNameId = jResp:string_of("samlNameId")
local defaultSignImage = jResp:string_of("defaultSignImage")
local notificationsProcedure = jResp:bool_of("notifications.procedure")
local fastSign = jResp:bool_of("fastSign")
local fullName = jResp:string_of("fullName")
local i = 0
local count_i = jResp:size_of_array("workspaces")
while i < count_i do
jResp.i = i
id = jResp:string_of("workspaces[i].id")
name = jResp:string_of("workspaces[i].name")
i = i + 1
end
i = 0
count_i = jResp:size_of_array("group.permissions")
while i < count_i do
jResp.i = i
strVal = jResp:string_of("group.permissions[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