Zig Requires Chilkat v11.0.0+
Zig
Aruba Fatturazione Elettronica Get Zip by Filename
See more Aruba Fatturazione Examples
Returns an invoice with all of its notifications in Zip format (e.g. IT01879020517_abcde.xml.p7m).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 GET https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m \
// -H "Accept: application/json" \
// -H "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="
// 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 NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" header.
http.setAuthToken("NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=");
http.setRequestHeader("Accept", "application/json");
const bd_zip = try chilkat.BinData.init();
defer bd_zip.deinit();
http.quickGetBd("https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m", bd_zip) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const resp_status_code = http.getLastStatus();
std.debug.print("response status code = {d}\n", .{resp_status_code});
if (resp_status_code != 200) {
// If it failed, the response body will not contain the .zip file data.
// It will likely contain an error message.
std.debug.print("{s}\n", .{try bd_zip.getString(alloc, "utf-8")});
std.debug.print("Failed.\n", .{});
return;
}
// Open the zip and extract the .p7m
const zip = try chilkat.Zip.init();
defer zip.deinit();
zip.openBd(bd_zip) catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
// If desired, we can unzip to the filesystem..
const num_unzipped = zip.unzip("c:/mySignedInvoices");
if (num_unzipped < 0) {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
}
// Alternatively, we can unzip into memory..
const entry = try chilkat.ZipEntry.init();
defer entry.deinit();
zip.entryAt(0, entry) catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
const bd_p7m = try chilkat.BinData.init();
defer bd_p7m.deinit();
entry.unzipToBd(bd_p7m) catch {
std.debug.print("{s}\n", .{try entry.getLastErrorText(alloc)});
return;
};
// Verify the signature and extract the XML from the p7m
// If the signature verification is successful, the contents of bdP7m are unwrapped and what
// remains is the original signed document..
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
crypt.opaqueVerifyBd(bd_p7m) catch {
std.debug.print("{s}\n", .{try crypt.getLastErrorText(alloc)});
return;
};
std.debug.print("The signature was verified.\n", .{});
// The bdp7m now contains the XML that was originally signed.
std.debug.print("Original XML:\n", .{});
std.debug.print("{s}\n", .{try bd_p7m.getString(alloc, "utf-8")});
}