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

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oQueryParams
LOCAL oResp
LOCAL oJarr
LOCAL oJson
LOCAL nClient_number
LOCAL nConsultant_number
LOCAL cId
LOCAL cName
LOCAL j
LOCAL nCount_j
LOCAL k
LOCAL nCount_k
LOCAL cStrVal
LOCAL i
LOCAL nCount_i

nSuccess := 0

oHttp := CreateObject("Chilkat.Http")

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

oQueryParams := CreateObject("Chilkat.JsonObject")
//  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.
oHttp:AuthToken := "REPLACE_BEARER_TOKEN"
oHttp:SetRequestHeader("accept", "application/json;charset=utf-8")
oHttp:SetRequestHeader("X-Datev-Client-ID", "DATEV_CLIENT_ID")

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpParams("GET", "https://accounting-clients.api.datev.de/platform-sandbox/v2/clients", oQueryParams, oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oQueryParams:destroy()
    oResp:destroy()
    RETURN
ENDIF

? Str(oResp:StatusCode)
? oResp:BodyStr

oJarr := CreateObject("Chilkat.JsonArray")

//  Insert code here to load the above JSON array into the jarr object.
oJarr:Load(oResp:BodyStr)

i := 0
nCount_i := oJarr:Size
DO WHILE i < nCount_i
    oJson := oJarr:ObjectAt(i)
    nClient_number := oJson:IntOf("client_number")
    nConsultant_number := oJson:IntOf("consultant_number")
    cId := oJson:StringOf("id")
    cName := oJson:StringOf("name")
    j := 0
    nCount_j := oJson:SizeOfArray("services")
    DO WHILE j < nCount_j
        oJson:J := j
        cName := oJson:StringOf("services[j].name")
        k := 0
        nCount_k := oJson:SizeOfArray("services[j].scopes")
        DO WHILE k < nCount_k
            oJson:K := k
            cStrVal := oJson:StringOf("services[j].scopes[k]")
            k := k + 1
        ENDDO
        j := j + 1
    ENDDO
    oJson:destroy()
    i := i + 1
ENDDO

oHttp:destroy()
oQueryParams:destroy()
oResp:destroy()
oJarr:destroy()