Sample code for 30+ languages & platforms
Zig Requires Chilkat v10.1.3+

Datev - Get a List of Clients

See more Datev Examples

Demonstrates how to get a list of clients in the accounting:clients Datev API.

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();

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Implements the following CURL command:

    // curl --request GET \
    //   --url "https://accounting-clients.api.datev.de/platform/v2/clients?filter=REPLACE_THIS_VALUE&skip=REPLACE_THIS_VALUE&top=REPLACE_THIS_VALUE" \
    //   --header "Authorization: Bearer REPLACE_BEARER_TOKEN" \
    //   --header "X-Datev-Client-ID: clientId" \
    //   --header "accept: application/json;charset=utf-8"

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

    const query_params = try chilkat.JsonObject.init();
    defer query_params.deinit();
    // ignore = queryParams.UpdateString("filter","REPLACE_THIS_VALUE");
    // ignore = queryParams.UpdateString("skip","REPLACE_THIS_VALUE");
    // ignore = queryParams.UpdateString("top","REPLACE_THIS_VALUE");

    // Adds the "Authorization: Bearer REPLACE_BEARER_TOKEN" header.
    http.setAuthToken("REPLACE_BEARER_TOKEN");
    http.setRequestHeader("accept", "application/json;charset=utf-8");
    http.setRequestHeader("X-Datev-Client-ID", "DATEV_CLIENT_ID");

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpParams("GET", "https://accounting-clients.api.datev.de/platform-sandbox/v2/clients", query_params, resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("{d}\n", .{resp.getStatusCode()});
    std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});

    const jarr = try chilkat.JsonArray.init();
    defer jarr.deinit();

    // Insert code here to load the above JSON array into the jarr object.
    jarr.load(try resp.getBodyStr(alloc)) catch {};

    var client_number: i32 = 0;
    var consultant_number: i32 = 0;
    var id: [:0]const u8 = "";
    var name: [:0]const u8 = "";
    var j: i32 = 0;
    var count_j: i32 = 0;
    var k: i32 = 0;
    var count_k: i32 = 0;
    var str_val: [:0]const u8 = "";

    var i: i32 = 0;
    const count_i = jarr.getSize();
    while (i < count_i) {
        const json = try jarr.objectAt(i);
        defer json.deinit();
        client_number = json.intOf("client_number");
        consultant_number = json.intOf("consultant_number");
        id = try json.stringOf(alloc, "id");
        name = try json.stringOf(alloc, "name");
        j = 0;
        count_j = json.sizeOfArray("services");
        while (j < count_j) {
            json.setJ(j);
            name = try json.stringOf(alloc, "services[j].name");
            k = 0;
            count_k = json.sizeOfArray("services[j].scopes");
            while (k < count_k) {
                json.setK(k);
                str_val = try json.stringOf(alloc, "services[j].scopes[k]");
                k = k + 1;
            }

            j = j + 1;
        }

        i = i + 1;
    }
}