delphiDll / easybill REST API / Create time tracking
Back to Collection Items
var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
date_from_at: HCkDtObj;
date_thru_at: HCkDtObj;
description: PWideChar;
cleared_at: PWideChar;
created_at: PWideChar;
hourly_rate: Integer;
id: PWideChar;
note: PWideChar;
v_number: PWideChar;
position_id: PWideChar;
project_id: PWideChar;
login_id: PWideChar;
timer_value: PWideChar;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "description": "<string>",
// "cleared_at": null,
// "created_at": "<dateTime>",
// "date_from_at": null,
// "date_thru_at": null,
// "hourly_rate": 0,
// "id": "<long>",
// "note": null,
// "number": "<string>",
// "position_id": null,
// "project_id": null,
// "login_id": "<long>",
// "timer_value": null
// }
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'description','<string>');
CkJsonObject_UpdateNull(json,'cleared_at');
CkJsonObject_UpdateString(json,'created_at','<dateTime>');
CkJsonObject_UpdateNull(json,'date_from_at');
CkJsonObject_UpdateNull(json,'date_thru_at');
CkJsonObject_UpdateInt(json,'hourly_rate',0);
CkJsonObject_UpdateString(json,'id','<long>');
CkJsonObject_UpdateNull(json,'note');
CkJsonObject_UpdateString(json,'number','<string>');
CkJsonObject_UpdateNull(json,'position_id');
CkJsonObject_UpdateNull(json,'project_id');
CkJsonObject_UpdateString(json,'login_id','<long>');
CkJsonObject_UpdateNull(json,'timer_value');
CkHttp_SetRequestHeader(http,'Content-Type','application/json');
CkHttp_SetRequestHeader(http,'Authorization','{{apiKey}}');
CkHttp_SetRequestHeader(http,'Accept','application/json');
resp := CkHttp_PostJson3(http,'https://api.easybill.de/rest/v1/time-trackings','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));
respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkHttpResponse__header(resp));
Memo1.Lines.Add('Failed.');
CkHttpResponse_Dispose(resp);
Exit;
end;
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "description": "<string>",
// "cleared_at": null,
// "created_at": "<dateTime>",
// "date_from_at": null,
// "date_thru_at": null,
// "hourly_rate": 0,
// "id": "<long>",
// "note": null,
// "number": "<string>",
// "position_id": null,
// "project_id": null,
// "login_id": "<long>",
// "timer_value": null
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
date_from_at := CkDtObj_Create();
date_thru_at := CkDtObj_Create();
description := CkJsonObject__stringOf(jResp,'description');
cleared_at := CkJsonObject__stringOf(jResp,'cleared_at');
created_at := CkJsonObject__stringOf(jResp,'created_at');
CkJsonObject_DtOf(jResp,'date_from_at',False,date_from_at);
CkJsonObject_DtOf(jResp,'date_thru_at',False,date_thru_at);
hourly_rate := CkJsonObject_IntOf(jResp,'hourly_rate');
id := CkJsonObject__stringOf(jResp,'id');
note := CkJsonObject__stringOf(jResp,'note');
v_number := CkJsonObject__stringOf(jResp,'number');
position_id := CkJsonObject__stringOf(jResp,'position_id');
project_id := CkJsonObject__stringOf(jResp,'project_id');
login_id := CkJsonObject__stringOf(jResp,'login_id');
timer_value := CkJsonObject__stringOf(jResp,'timer_value');
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
CkDtObj_Dispose(date_from_at);
CkDtObj_Dispose(date_thru_at);
Curl Command
curl -X POST
-H "Authorization: {{apiKey}}"
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"description": "<string>",
"cleared_at": null,
"created_at": "<dateTime>",
"date_from_at": null,
"date_thru_at": null,
"hourly_rate": 0,
"id": "<long>",
"note": null,
"number": "<string>",
"position_id": null,
"project_id": null,
"login_id": "<long>",
"timer_value": null
}'
https://api.easybill.de/rest/v1/time-trackings
Postman Collection Item JSON
{
"name": "Create time tracking",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"<string>\",\n \"cleared_at\": null,\n \"created_at\": \"<dateTime>\",\n \"date_from_at\": null,\n \"date_thru_at\": null,\n \"hourly_rate\": 0,\n \"id\": \"<long>\",\n \"note\": null,\n \"number\": \"<string>\",\n \"position_id\": null,\n \"project_id\": null,\n \"login_id\": \"<long>\",\n \"timer_value\": null\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/time-trackings",
"host": [
"{{baseUrl}}"
],
"path": [
"time-trackings"
]
}
},
"response": [
{
"name": "Successful operation",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "Authorization",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"<string>\",\n \"cleared_at\": null,\n \"created_at\": \"<dateTime>\",\n \"date_from_at\": null,\n \"date_thru_at\": null,\n \"hourly_rate\": 0,\n \"id\": \"<long>\",\n \"note\": null,\n \"number\": \"<string>\",\n \"position_id\": null,\n \"project_id\": null,\n \"login_id\": \"<long>\",\n \"timer_value\": null\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/time-trackings",
"host": [
"{{baseUrl}}"
],
"path": [
"time-trackings"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"description\": \"<string>\",\n \"cleared_at\": null,\n \"created_at\": \"<dateTime>\",\n \"date_from_at\": null,\n \"date_thru_at\": null,\n \"hourly_rate\": 0,\n \"id\": \"<long>\",\n \"note\": null,\n \"number\": \"<string>\",\n \"position_id\": null,\n \"project_id\": null,\n \"login_id\": \"<long>\",\n \"timer_value\": null\n}"
},
{
"name": "Too Many Requests",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "Authorization",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"<string>\",\n \"cleared_at\": null,\n \"created_at\": \"<dateTime>\",\n \"date_from_at\": null,\n \"date_thru_at\": null,\n \"hourly_rate\": 0,\n \"id\": \"<long>\",\n \"note\": null,\n \"number\": \"<string>\",\n \"position_id\": null,\n \"project_id\": null,\n \"login_id\": \"<long>\",\n \"timer_value\": null\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/time-trackings",
"host": [
"{{baseUrl}}"
],
"path": [
"time-trackings"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "text",
"header": [
],
"cookie": [
],
"body": ""
}
]
}