Sample code for 30+ languages & platforms
Zig

Aruba Fatturazione Elettronica userinfo

See more Aruba Fatturazione Examples

This method lets you retrieve user information relating to the authentication token.

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://auth.fatturazioneelettronica.aruba.it/auth/userInfo \
    //   -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=");

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    http.quickGetSb("https://auth.fatturazioneelettronica.aruba.it/auth/userInfo", 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)

    // {
    //   "username": "ARUBA0000",
    //   "pec": "pec@pec.it",
    //   "userDescription": "Aruba PEC S.p.A.",
    //   "countryCode": "IT",
    //   "vatCode": "01879020517",
    //   "fiscalCode": "01879020517",
    //   "accountStatus": {
    //     "expired": false,
    //     "expirationDate": "2020-10-10"
    //   },
    //   "usageStatus": {
    //     "usedSpaceKB": 262144,
    //     "maxSpaceKB": 1048576
    //   }
    // }

    // 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, "username");
    _ = try j_resp.stringOf(alloc, "pec");
    _ = try j_resp.stringOf(alloc, "userDescription");
    _ = try j_resp.stringOf(alloc, "countryCode");
    _ = try j_resp.stringOf(alloc, "vatCode");
    _ = try j_resp.stringOf(alloc, "fiscalCode");
    _ = j_resp.boolOf("accountStatus.expired");
    _ = try j_resp.stringOf(alloc, "accountStatus.expirationDate");
    _ = j_resp.intOf("usageStatus.usedSpaceKB");
    _ = j_resp.intOf("usageStatus.maxSpaceKB");
}