Sample code for 30+ languages & platforms
Zig

Aruba Fatturazione Elettronica Find Invoice by Username

See more Aruba Fatturazione Examples

Finds a list of invoices. Returns invoices without content in base64 (lazy loading)

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/in/findByUsername?username=Username \
    //   -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/in/findByUsername?username=Username", sb_response_body) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    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 = http.getLastStatus();
    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 http.getLastHeader(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "errorCode": "0000",
    //   "errorDescription": null,
    //   "content": [
    //     {
    //       "errorCode": null,
    //       "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": null,
    //       "filename": "IT01879020517_jtlk0.xml.p7m",
    //       "invoices": [
    //         {
    //           "invoiceDate": "2020-07-10T09:19:56.948+02:00",
    //           "number": "2020/0001",
    //           "status": "Inviata",
    //           "statusDescription": ""
    //         }
    //       ],
    //       "username": "Utente",
    //       "lastUpdate": "2020-07-10T07:19:56.948+0000",
    //       "creationDate": "2020-07-10T07:19:56.948+0000",
    //       "idSdi": "11110",
    //       "pddAvailable": true
    //     },
    //     {
    //       "errorCode": null,
    //       "errorDescription": null,
    //       "id": "2",
    //       "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": null,
    //       "filename": "IT01879020517_jtlk1.xml.p7m",
    //       "invoices": [
    //         {
    //           "invoiceDate": "2020-07-10T09:19:56.948+02:00",
    //           "number": "2020/0002",
    //           "status": "Inviata",
    //           "statusDescription": ""
    //         }
    //       ],
    //       "username": "Utente",
    //       "lastUpdate": "2020-07-10T07:19:56.948+0000",
    //       "creationDate": "2020-07-10T07:19:56.948+0000",
    //       "idSdi": "11111",
    //       "pddAvailable": true
    //     },
    //     {
    //       "errorCode": null,
    //       "errorDescription": null,
    //       "id": "3",
    //       "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": null,
    //       "filename": "IT01879020517_jtlk2.xml.p7m",
    //       "invoices": [
    //         {
    //           "invoiceDate": "2020-07-10T09:19:56.948+02:00",
    //           "number": "2020/0003",
    //           "status": "Inviata",
    //           "statusDescription": ""
    //         }
    //       ],
    //       "username": "Utente",
    //       "lastUpdate": "2020-07-10T07:19:56.948+0000",
    //       "creationDate": "2020-07-10T07:19:56.948+0000",
    //       "idSdi": "11112",
    //       "pddAvailable": true
    //     },
    //     {
    //       "errorCode": null,
    //       "errorDescription": null,
    //       "id": "4",
    //       "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": null,
    //       "filename": "IT01879020517_jtlk3.xml.p7m",
    //       "invoices": [
    //         {
    //           "invoiceDate": "2020-07-10T09:19:56.948+02:00",
    //           "number": "2020/0004",
    //           "status": "Inviata",
    //           "statusDescription": ""
    //         }
    //       ],
    //       "username": "Utente",
    //       "lastUpdate": "2020-07-10T07:19:56.948+0000",
    //       "creationDate": "2020-07-10T07:19:56.948+0000",
    //       "idSdi": "11113",
    //       "pddAvailable": true
    //     }
    //   ],
    //   "last": true,
    //   "totalElements": 4,
    //   "totalPages": 1,
    //   "size": 10,
    //   "number": 1,
    //   "first": true,
    //   "numberOfElements": 4
    // }

    // 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 id: [:0]const u8 = "";
    var sender_description: [:0]const u8 = "";
    var sender_country_code: [:0]const u8 = "";
    var sender_vat_code: [:0]const u8 = "";
    var sender_fiscal_code: [:0]const u8 = "";
    var receiver_description: [:0]const u8 = "";
    var receiver_country_code: [:0]const u8 = "";
    var receiver_vat_code: [:0]const u8 = "";
    var receiver_fiscal_code: [:0]const u8 = "";
    var invoice_type: [:0]const u8 = "";
    var doc_type: [:0]const u8 = "";
    var file: [:0]const u8 = "";
    var filename: [:0]const u8 = "";
    var username: [:0]const u8 = "";
    var last_update: [:0]const u8 = "";
    var creation_date: [:0]const u8 = "";
    var id_sdi: [:0]const u8 = "";
    var pdd_available: bool = false;
    var j: i32 = 0;
    var count_j: i32 = 0;
    var invoice_date: [:0]const u8 = "";
    var number_str: [:0]const u8 = "";
    var status: [:0]const u8 = "";
    var status_description: [:0]const u8 = "";

    var error_code: [:0]const u8 = try j_resp.stringOf(alloc, "errorCode");
    var error_description: [:0]const u8 = try j_resp.stringOf(alloc, "errorDescription");
    _ = j_resp.boolOf("last");
    _ = j_resp.intOf("totalElements");
    _ = j_resp.intOf("totalPages");
    _ = j_resp.intOf("size");
    _ = j_resp.intOf("number");
    _ = j_resp.boolOf("first");
    _ = j_resp.intOf("numberOfElements");
    var i: i32 = 0;
    const count_i = j_resp.sizeOfArray("content");
    while (i < count_i) {
        j_resp.setI(i);
        error_code = try j_resp.stringOf(alloc, "content[i].errorCode");
        error_description = try j_resp.stringOf(alloc, "content[i].errorDescription");
        id = try j_resp.stringOf(alloc, "content[i].id");
        sender_description = try j_resp.stringOf(alloc, "content[i].sender.description");
        sender_country_code = try j_resp.stringOf(alloc, "content[i].sender.countryCode");
        sender_vat_code = try j_resp.stringOf(alloc, "content[i].sender.vatCode");
        sender_fiscal_code = try j_resp.stringOf(alloc, "content[i].sender.fiscalCode");
        receiver_description = try j_resp.stringOf(alloc, "content[i].receiver.description");
        receiver_country_code = try j_resp.stringOf(alloc, "content[i].receiver.countryCode");
        receiver_vat_code = try j_resp.stringOf(alloc, "content[i].receiver.vatCode");
        receiver_fiscal_code = try j_resp.stringOf(alloc, "content[i].receiver.fiscalCode");
        invoice_type = try j_resp.stringOf(alloc, "content[i].invoiceType");
        doc_type = try j_resp.stringOf(alloc, "content[i].docType");
        file = try j_resp.stringOf(alloc, "content[i].file");
        filename = try j_resp.stringOf(alloc, "content[i].filename");
        username = try j_resp.stringOf(alloc, "content[i].username");
        last_update = try j_resp.stringOf(alloc, "content[i].lastUpdate");
        creation_date = try j_resp.stringOf(alloc, "content[i].creationDate");
        id_sdi = try j_resp.stringOf(alloc, "content[i].idSdi");
        pdd_available = j_resp.boolOf("content[i].pddAvailable");
        j = 0;
        count_j = j_resp.sizeOfArray("content[i].invoices");
        while (j < count_j) {
            j_resp.setJ(j);
            invoice_date = try j_resp.stringOf(alloc, "content[i].invoices[j].invoiceDate");
            number_str = try j_resp.stringOf(alloc, "content[i].invoices[j].number");
            status = try j_resp.stringOf(alloc, "content[i].invoices[j].status");
            status_description = try j_resp.stringOf(alloc, "content[i].invoices[j].statusDescription");
            j = j + 1;
        }

        i = i + 1;
    }
}