Lua
Lua
Yousign: Download Information about Previously Uploaded File
See more Yousign Examples
Demonstrates how to download the information (in JSON format) about a file previously uploaded.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/files/{{id}}' \
-- --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/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", 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": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
-- "name": "The best name for my file.pdf",
-- "type": "signable",
-- "contentType": "application/pdf",
-- "description": null,
-- "createdAt": "2018-12-07T08:10:21+01:00",
-- "updatedAt": "2018-12-07T08:10:21+01:00",
-- "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2",
-- "metadata": [
-- ],
-- "workspace": "/workspaces/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
-- "creator": null,
-- "protected": false,
-- "position": 0,
-- "parent": null
-- }
-- 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 id = jResp:string_of("id")
local name = jResp:string_of("name")
local v_type = jResp:string_of("type")
local contentType = jResp:string_of("contentType")
local description = jResp:string_of("description")
local createdAt = jResp:string_of("createdAt")
local updatedAt = jResp:string_of("updatedAt")
local sha256 = jResp:string_of("sha256")
local workspace = jResp:string_of("workspace")
local creator = jResp:string_of("creator")
local v_protected = jResp:bool_of("protected")
local position = jResp:int_of("position")
local parent = jResp:string_of("parent")
local i = 0
local count_i = jResp:size_of_array("metadata")
while i < count_i do
jResp.i = i
i = i + 1
end