Zig
Zig
Aruba Fatturazione Elettronica CreateTransmissionRequestList
See more Aruba Fatturazione Examples
Creation of "Financial Communications" transmission request in zip format.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// 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.
const zip = try chilkat.Zip.init();
defer zip.deinit();
// 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.newZip("x.zip") catch {};
// Append references to XML files to the zip object in memory.
const recurse = false;
zip.appendFiles("qa_data/aruba/*.xml", recurse) catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
// Write the zip archive into the bdZip object.
const bd_zip = try chilkat.BinData.init();
defer bd_zip.deinit();
zip.writeBd(bd_zip) catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
// Get the zip in base64 format.
const zip_as_base64 = try bd_zip.getEncoded(alloc, "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=="
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("userName", "ARUBA0000") catch {};
json.updateString("password", "ArubaPwd") catch {};
json.updateString("userID", "ARUBA0000") catch {};
json.updateString("comunicationType", "LI") catch {};
json.updateString("dataFile", zip_as_base64) catch {};
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
http.setRequestHeader("Accept", "application/json");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
resp.getBodySb(sb_response_body) catch {};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = resp.getStatusCode();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// 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
var file_name: [:0]const u8 = "";
_ = try j_resp.stringOf(alloc, "errorCode");
_ = try j_resp.stringOf(alloc, "errorDescription");
var request_id: [:0]const u8 = try j_resp.stringOf(alloc, "requestID");
var i: i32 = 0;
const count_i = j_resp.sizeOfArray("requestIDList");
while (i < count_i) {
j_resp.setI(i);
file_name = try j_resp.stringOf(alloc, "requestIDList[i].fileName");
request_id = try j_resp.stringOf(alloc, "requestIDList[i].requestID");
i = i + 1;
}
}