Sample code for 30+ languages & platforms
PureBasic

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

PureBasic
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonArray.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; 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

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; 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.
    CkHttp::setCkAuthToken(http, "REPLACE_BEARER_TOKEN")
    CkHttp::ckSetRequestHeader(http,"accept","application/json;charset=utf-8")
    CkHttp::ckSetRequestHeader(http,"X-Datev-Client-ID","DATEV_CLIENT_ID")

    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpParams(http,"GET","https://accounting-clients.api.datev.de/platform-sandbox/v2/clients",queryParams,resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)

    jarr.i = CkJsonArray::ckCreate()
    If jarr.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Insert code here to load the above JSON array into the jarr object.
    CkJsonArray::ckLoad(jarr,CkHttpResponse::ckBodyStr(resp))

    json.i
    client_number.i
    consultant_number.i
    id.s
    name.s
    j.i
    count_j.i
    k.i
    count_k.i
    strVal.s

    i.i = 0
    count_i.i = CkJsonArray::ckSize(jarr)
    While i < count_i
        json = CkJsonArray::ckObjectAt(jarr,i)
        client_number = CkJsonObject::ckIntOf(json,"client_number")
        consultant_number = CkJsonObject::ckIntOf(json,"consultant_number")
        id = CkJsonObject::ckStringOf(json,"id")
        name = CkJsonObject::ckStringOf(json,"name")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(json,"services")
        While j < count_j
            CkJsonObject::setCkJ(json, j)
            name = CkJsonObject::ckStringOf(json,"services[j].name")
            k = 0
            count_k = CkJsonObject::ckSizeOfArray(json,"services[j].scopes")
            While k < count_k
                CkJsonObject::setCkK(json, k)
                strVal = CkJsonObject::ckStringOf(json,"services[j].scopes[k]")
                k = k + 1
            Wend
            j = j + 1
        Wend
        CkJsonObject::ckDispose(json)

        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkHttpResponse::ckDispose(resp)
    CkJsonArray::ckDispose(jarr)


    ProcedureReturn
EndProcedure