Zig
Zig
Aruba Fatturazione Elettronica Upload Invoice
See more Aruba Fatturazione Examples
This method must be used by the EO to send an invoice in XML format in accordance with AGID standards, but not yet digitally signed.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/invoice/upload \
// -H "Accept: application/json" \
// -H "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" \
// -H "Content-Type: application/json;charset=UTF-8" \
// -d '{
// "dataFile" : "dGVzdA==",
// "credential" : "",
// "domain" : ""
// }'
// 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.
// {
// "dataFile": "dGVzdA==",
// "credential": "",
// "domain": ""
// }
// The dataFile field must contain an XML invoice not yet digitally signed.
const sb_invoice_xml = try chilkat.StringBuilder.init();
defer sb_invoice_xml.deinit();
try sb_invoice_xml.loadFile("qa_data/aruba/invoice123.xml", "utf-8");
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("dataFile", try sb_invoice_xml.getEncoded(alloc, "base64", "utf-8")) catch {};
json.updateString("credential", "") catch {};
json.updateString("domain", "") catch {};
http.setRequestHeader("Accept", "application/json");
// Adds the "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" header.
http.setAuthToken("NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=");
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://ws.fatturazioneelettronica.aruba.it/services/invoice/upload", 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": "0000",
// "errorDescription": "Operazione effettuata - 521e052902be7b879d41e0fd586f0e21",
// "uploadFileName": "IT06491598644_zbvbd.xml.p7m"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
_ = try j_resp.stringOf(alloc, "errorCode");
_ = try j_resp.stringOf(alloc, "errorDescription");
_ = try j_resp.stringOf(alloc, "uploadFileName");
}