Sample code for 30+ languages & platforms
Zig

Aruba Fatturazione Elettronica getByIdSdi

See more Aruba Fatturazione Examples

This method returns the complete status detail of an electronic invoice. Search for a single invoice by SdI identifier.

Chilkat Zig Downloads

Zig
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/out/getByIdSdi?idSdi=11110&includePdf=true \
    //   -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 sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    http.quickGetSb("https://ws.fatturazioneelettronica.aruba.it/services/invoice/out/getByIdSdi?idSdi=11110&includePdf=true", sb_response_body) 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});

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.loadSb(sb_response_body) catch {};
    json.setEmitCompact(true);

    std.debug.print("Response JSON:\n", .{});
    std.debug.print("{s}\n", .{try json.emit(alloc)});

    if (resp_status_code != 200) {
        std.debug.print("Failed.\n", .{});
        return;
    }

    // Sample response:

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    // {
    //   "errorCode" : "0000",
    //   "errorDescription" : null,
    //   "id" : "1",
    //   "sender" : {
    //     "description" : "Aruba SPA",
    //     "countryCode" : "IT",
    //     "vatCode" : "22222222",
    //     "fiscalCode" : "11111111111"
    //   },
    //   "receiver" : {
    //     "description" : "Aruba SPA",
    //     "countryCode" : "IT",
    //     "vatCode" : "4444444",
    //     "fiscalCode" : "333333333"
    //   },
    //   "invoiceType" : "FPR12",
    //   "docType" : "in",
    //   "file" : "dGVzdA==",
    //   "filename" : "IT01879020517_jtlk0.xml.p7m",
    //   "invoices" : [ {
    //     "invoiceDate" : "2021-08-24T12:35:45.363+02:00",
    //     "number" : "2021/0001",
    //     "status" : "Inviata",
    //     "statusDescription" : ""
    //   } ],
    //   "username" : "Utente",
    //   "lastUpdate" : "2021-08-24T10:35:45.363+0000",
    //   "creationDate" : "2021-08-24T10:35:45.363+0000",
    //   "idSdi" : "11110",
    //   "pdfFile" : "ZEdWemRGQmtaZz09",
    //   "pddAvailable" : true
    // }
    //

    var invoice_date: [:0]const u8 = "";
    var number: [:0]const u8 = "";
    var status: [:0]const u8 = "";
    var status_description: [:0]const u8 = "";

    _ = try json.stringOf(alloc, "errorCode");
    _ = try json.stringOf(alloc, "errorDescription");
    _ = try json.stringOf(alloc, "id");
    _ = try json.stringOf(alloc, "sender.description");
    _ = try json.stringOf(alloc, "sender.countryCode");
    _ = try json.stringOf(alloc, "sender.vatCode");
    _ = try json.stringOf(alloc, "sender.fiscalCode");
    _ = try json.stringOf(alloc, "receiver.description");
    _ = try json.stringOf(alloc, "receiver.countryCode");
    _ = try json.stringOf(alloc, "receiver.vatCode");
    _ = try json.stringOf(alloc, "receiver.fiscalCode");
    _ = try json.stringOf(alloc, "invoiceType");
    _ = try json.stringOf(alloc, "docType");
    _ = try json.stringOf(alloc, "file");
    _ = try json.stringOf(alloc, "filename");
    _ = try json.stringOf(alloc, "username");
    _ = try json.stringOf(alloc, "lastUpdate");
    _ = try json.stringOf(alloc, "creationDate");
    _ = try json.stringOf(alloc, "idSdi");
    _ = try json.stringOf(alloc, "pdfFile");
    _ = json.boolOf("pddAvailable");
    var i: i32 = 0;
    const count_i = json.sizeOfArray("invoices");
    while (i < count_i) {
        json.setI(i);
        invoice_date = try json.stringOf(alloc, "invoices[i].invoiceDate");
        number = try json.stringOf(alloc, "invoices[i].number");
        status = try json.stringOf(alloc, "invoices[i].status");
        status_description = try json.stringOf(alloc, "invoices[i].statusDescription");
        i = i + 1;
    }
}