Sample code for 30+ languages & platforms
Zig

Cerved API Entity Contacts

See more Cerved Examples

The service returns the list of contacts of a Subject (legal entities) identified by "id_soggetto"

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://api.cerved.com/cervedApi/v1/entityProfile/contacts?id_soggetto=12345678 \
    //   -H 'accept: application/json' \
    //   -H 'apikey: ********************************'

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    http.setRequestHeader("accept", "application/json");
    http.setRequestHeader("apikey", "********************************");

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    http.quickGetSb("https://api.cerved.com/cervedApi/v1/entityProfile/contacts?id_soggetto=12345678", 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)

    // {
    //   "indirizzi_email": [
    //     {
    //       "email": "string",
    //       "categoria": "string"
    //     }
    //   ],
    //   "indirizzi_email_certificate": [
    //     {
    //       "email": "string",
    //       "categoria": "string"
    //     }
    //   ],
    //   "telefoni": [
    //     {
    //       "fonte": "string",
    //       "sede": "string",
    //       "numero": "string",
    //       "uso": "string"
    //     }
    //   ],
    //   "siti_web": [
    //     {
    //       "url": "string",
    //       "tipo": "string"
    //     }
    //   ]
    // }

    // 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 email: [:0]const u8 = "";
    var categoria: [:0]const u8 = "";
    var fonte: [:0]const u8 = "";
    var sede: [:0]const u8 = "";
    var numero: [:0]const u8 = "";
    var uso: [:0]const u8 = "";
    var url: [:0]const u8 = "";
    var tipo: [:0]const u8 = "";

    var i: i32 = 0;
    var count_i: i32 = j_resp.sizeOfArray("indirizzi_email");
    while (i < count_i) {
        j_resp.setI(i);
        email = try j_resp.stringOf(alloc, "indirizzi_email[i].email");
        categoria = try j_resp.stringOf(alloc, "indirizzi_email[i].categoria");
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("indirizzi_email_certificate");
    while (i < count_i) {
        j_resp.setI(i);
        email = try j_resp.stringOf(alloc, "indirizzi_email_certificate[i].email");
        categoria = try j_resp.stringOf(alloc, "indirizzi_email_certificate[i].categoria");
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("telefoni");
    while (i < count_i) {
        j_resp.setI(i);
        fonte = try j_resp.stringOf(alloc, "telefoni[i].fonte");
        sede = try j_resp.stringOf(alloc, "telefoni[i].sede");
        numero = try j_resp.stringOf(alloc, "telefoni[i].numero");
        uso = try j_resp.stringOf(alloc, "telefoni[i].uso");
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("siti_web");
    while (i < count_i) {
        j_resp.setI(i);
        url = try j_resp.stringOf(alloc, "siti_web[i].url");
        tipo = try j_resp.stringOf(alloc, "siti_web[i].tipo");
        i = i + 1;
    }
}