Chilkat Online Tools

TCL / easybill REST API / Create time tracking

Back to Collection Items

load ./chilkat.dll

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set http [new_CkHttp]

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

set json [new_CkJsonObject]

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 is a CkHttpResponse
set resp [CkHttp_PostJson3 $http "https://api.easybill.de/rest/v1/time-trackings" "application/json" $json]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    exit
}

set sbResponseBody [new_CkStringBuilder]

CkHttpResponse_GetBodySb $resp $sbResponseBody

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttpResponse_header $resp]
    puts "Failed."
    delete_CkHttpResponse $resp

    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

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

set date_from_at [new_CkDtObj]

set date_thru_at [new_CkDtObj]

set description [CkJsonObject_stringOf $jResp "description"]
set cleared_at [CkJsonObject_stringOf $jResp "cleared_at"]
set created_at [CkJsonObject_stringOf $jResp "created_at"]
CkJsonObject_DtOf $jResp "date_from_at" 0 $date_from_at
CkJsonObject_DtOf $jResp "date_thru_at" 0 $date_thru_at
set hourly_rate [CkJsonObject_IntOf $jResp "hourly_rate"]
set id [CkJsonObject_stringOf $jResp "id"]
set note [CkJsonObject_stringOf $jResp "note"]
set v_number [CkJsonObject_stringOf $jResp "number"]
set position_id [CkJsonObject_stringOf $jResp "position_id"]
set project_id [CkJsonObject_stringOf $jResp "project_id"]
set login_id [CkJsonObject_stringOf $jResp "login_id"]
set timer_value [CkJsonObject_stringOf $jResp "timer_value"]

delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
delete_CkDtObj $date_from_at
delete_CkDtObj $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": ""
    }
  ]
}