Lua
Lua
Aruba Fatturazione Elettronica CreateTransmissionRequestList
See more Aruba Fatturazione Examples
Creation of "Financial Communications" transmission request in zip format.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 -X POST https://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList \
-- -H "Accept: application/json" \
-- -H "Content-Type: application/json;charset=UTF-8" \
-- -d '{
-- "userName" : "ARUBA0000",
-- "password" : "ArubaPwd",
-- "userID" : "ARUBA0000",
-- "comunicationType" : "LI",
-- "dataFile" : "dGVzdA=="
-- }'
-- The dataFile must contain a Zip file, containing xml files which conform to the Revenue Agency specifications.
-- The archive file must be Base64 codified and contain a CADES-based electronic signature.
local zip = chilkat.Zip.new()
-- Initialize the zip object. Because we will never actually write a zip file to the filesystem,
-- the filepath passed to NewZip does not matter.
zip:new_zip("x.zip")
-- Append references to XML files to the zip object in memory.
local recurse = false
local success = zip:append_files("qa_data/aruba/*.xml", recurse)
if not success then
print(zip.last_error_text)
return
end
-- Write the zip archive into the bdZip object.
local bdZip = chilkat.BinData.new()
success = zip:write_bd(bdZip)
if not success then
print(zip.last_error_text)
return
end
-- Get the zip in base64 format.
local zipAsBase64 = bdZip:get_encoded("base64")
-- 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.
-- {
-- "userName": "ARUBA0000",
-- "password": "ArubaPwd",
-- "userID": "ARUBA0000",
-- "comunicationType": "LI",
-- "dataFile": "dGVzdA=="
-- }
local json = chilkat.JsonObject.new()
json:update_string("userName", "ARUBA0000")
json:update_string("password", "ArubaPwd")
json:update_string("userID", "ARUBA0000")
json:update_string("comunicationType", "LI")
json:update_string("dataFile", zipAsBase64)
http:set_request_header("Content-Type", "application/json;charset=UTF-8")
http:set_request_header("Accept", "application/json")
local resp = chilkat.HttpResponse.new()
success = http:http_json("POST", "https://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList", 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)
-- {
-- "errorCode": "",
-- "errorDescription": "",
-- "requestID": "C70WC0SIPQ1JISWQ",
-- "requestIDList": [
-- {
-- "fileName": "ITADFSREETDSD_LI_0001.xml",
-- "requestID": "TXZWQPVYVFJHRUKN"
-- },
-- {
-- "fileName": "ITADFSREETDSD_LI_0002.xml",
-- "requestID": "PRSGFITDHFPTJ8OO"
-- },
-- {
-- "fileName": "ITADFSREETDSD_LI_0003.xml",
-- "requestID": "QNJ9E2MWGYGSM22Q"
-- }
-- ]
-- }
-- 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 fileName = ""
local errorCode = jResp:string_of("errorCode")
local errorDescription = jResp:string_of("errorDescription")
local requestID = jResp:string_of("requestID")
local i = 0
local count_i = jResp:size_of_array("requestIDList")
while i < count_i do
jResp.i = i
fileName = jResp:string_of("requestIDList[i].fileName")
requestID = jResp:string_of("requestIDList[i].requestID")
i = i + 1
end