Sample code for 30+ languages & platforms
Lua 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 Lua Downloads

Lua
local chilkat = require("chilkat")

local http = chilkat.Http.new()

-- 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

local queryParams = chilkat.JsonObject.new()
-- 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.auth_token = "REPLACE_BEARER_TOKEN"
http:set_request_header("accept", "application/json;charset=utf-8")
http:set_request_header("X-Datev-Client-ID", "DATEV_CLIENT_ID")

local resp = chilkat.HttpResponse.new()
local success = http:http_params("GET", "https://accounting-clients.api.datev.de/platform-sandbox/v2/clients", queryParams, resp)
if not success then
    print(http.last_error_text)
    return
end

print(resp.status_code)
print(resp.body_str)

local jarr = chilkat.JsonArray.new()

-- Insert code here to load the above JSON array into the jarr object.
jarr:load(resp.body_str)

local json
local client_number = 0
local consultant_number = 0
local id = ""
local name = ""
local j = 0
local count_j = 0
local k = 0
local count_k = 0
local strVal = ""

local i = 0
local count_i = jarr.size
while i < count_i do
    json = jarr:object_at(i)
    client_number = json:int_of("client_number")
    consultant_number = json:int_of("consultant_number")
    id = json:string_of("id")
    name = json:string_of("name")
    j = 0
    count_j = json:size_of_array("services")
    while j < count_j do
        json.j = j
        name = json:string_of("services[j].name")
        k = 0
        count_k = json:size_of_array("services[j].scopes")
        while k < count_k do
            json.k = k
            strVal = json:string_of("services[j].scopes[k]")
            k = k + 1
        end

        j = j + 1
    end

    i = i + 1
end