Java Requires Chilkat v10.1.3+
Chilkat2 Java
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 Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonArray;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
Http http = new 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
JsonObject queryParams = new 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.
http.setAuthToken("REPLACE_BEARER_TOKEN");
http.setRequestHeader("accept", "application/json;charset=utf-8");
http.setRequestHeader("X-Datev-Client-ID", "DATEV_CLIENT_ID");
HttpResponse resp = new HttpResponse();
try {
http.httpParams("GET", "https://accounting-clients.api.datev.de/platform-sandbox/v2/clients", queryParams, resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println(resp.getStatusCode());
System.out.println(resp.getBodyStr());
JsonArray jarr = new JsonArray();
// Insert code here to load the above JSON array into the jarr object.
jarr.load(resp.getBodyStr());
JsonObject json = null;
int client_number = 0;
int consultant_number = 0;
String id = "";
String name = "";
int j = 0;
int count_j = 0;
int k = 0;
int count_k = 0;
String strVal = "";
int i = 0;
int count_i = jarr.getSize();
while (i < count_i) {
json = jarr.objectAt(i);
client_number = json.intOf("client_number");
consultant_number = json.intOf("consultant_number");
id = json.stringOf("id");
name = json.stringOf("name");
j = 0;
count_j = json.sizeOfArray("services");
while (j < count_j) {
json.setJ(j);
name = json.stringOf("services[j].name");
k = 0;
count_k = json.sizeOfArray("services[j].scopes");
while (k < count_k) {
json.setK(k);
strVal = json.stringOf("services[j].scopes[k]");
k = k + 1;
}
j = j + 1;
}
json.close();
i = i + 1;
}
}
}