PowerBuilder / New FreshBooks / Update a Time Entry
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
integer li_Id
integer li_Identity_id
string ls_Timer
integer li_Is_logged
string ls_Started_at
string ls_Created_at
integer li_Duration
integer li_Client_id
integer li_Project_id
string ls_Pending_client
string ls_Pending_project
string ls_Pending_task
string ls_Task_id
string ls_Service_id
string ls_Note
integer li_Active
integer li_Billable
integer li_Billed
integer li_Internal
string ls_Retainer_id
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "time_entry": {
// "is_logged": true,
// "duration": 600,
// "note": "Updated Note",
// "started_at": "2016-08-16T18:03:28.000Z",
// "timer": {
// "id": "2936"
// },
// "client_id": 123,
// "project_id": 123
// }
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateBool("time_entry.is_logged",1)
loo_Json.UpdateInt("time_entry.duration",600)
loo_Json.UpdateString("time_entry.note","Updated Note")
loo_Json.UpdateString("time_entry.started_at","2016-08-16T18:03:28.000Z")
loo_Json.UpdateString("time_entry.timer.id","2936")
loo_Json.UpdateInt("time_entry.client_id",123)
loo_Json.UpdateInt("time_entry.project_id",123)
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Http.SetRequestHeader("Content-Type","")
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json.EmitSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("PUT","https://api.freshbooks.com/timetracking/business/{{businessId}}/time_entries/{{timeEntryId}}",loo_SbRequestBody,"utf-8","",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "time_entry": {
// "id": 47902064,
// "identity_id": 1882548,
// "timer": null,
// "is_logged": true,
// "started_at": "2016-08-16T18:03:28Z",
// "created_at": "2019-04-24T18:44:50Z",
// "duration": 600,
// "client_id": 31006,
// "project_id": 2989082,
// "pending_client": null,
// "pending_project": null,
// "pending_task": null,
// "task_id": null,
// "service_id": null,
// "note": "Updated Note",
// "active": true,
// "billable": false,
// "billed": false,
// "internal": false,
// "retainer_id": null
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
li_Id = loo_JResp.IntOf("time_entry.id")
li_Identity_id = loo_JResp.IntOf("time_entry.identity_id")
ls_Timer = loo_JResp.StringOf("time_entry.timer")
li_Is_logged = loo_JResp.BoolOf("time_entry.is_logged")
ls_Started_at = loo_JResp.StringOf("time_entry.started_at")
ls_Created_at = loo_JResp.StringOf("time_entry.created_at")
li_Duration = loo_JResp.IntOf("time_entry.duration")
li_Client_id = loo_JResp.IntOf("time_entry.client_id")
li_Project_id = loo_JResp.IntOf("time_entry.project_id")
ls_Pending_client = loo_JResp.StringOf("time_entry.pending_client")
ls_Pending_project = loo_JResp.StringOf("time_entry.pending_project")
ls_Pending_task = loo_JResp.StringOf("time_entry.pending_task")
ls_Task_id = loo_JResp.StringOf("time_entry.task_id")
ls_Service_id = loo_JResp.StringOf("time_entry.service_id")
ls_Note = loo_JResp.StringOf("time_entry.note")
li_Active = loo_JResp.BoolOf("time_entry.active")
li_Billable = loo_JResp.BoolOf("time_entry.billable")
li_Billed = loo_JResp.BoolOf("time_entry.billed")
li_Internal = loo_JResp.BoolOf("time_entry.internal")
ls_Retainer_id = loo_JResp.StringOf("time_entry.retainer_id")
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-H "Content-Type: "
-d '{
"time_entry": {
"is_logged": true,
"duration": 600,
"note": "Updated Note",
"started_at": "2016-08-16T18:03:28.000Z",
"timer": {
"id": "2936"
},
"client_id": {{clientId}},
"project_id": {{projectId}}
}
}'
https://api.freshbooks.com/timetracking/business/{{businessId}}/time_entries/{{timeEntryId}}
Postman Collection Item JSON
{
"name": "Update a Time Entry",
"request": {
"method": "PUT",
"header": [
{
"key": "",
"name": "Content-Type",
"value": "",
"type": "text",
"disabled": true
},
{
"key": "Content-Type",
"value": "",
"disabled": true
}
],
"body": {
"mode": "raw",
"raw": "{\n \"time_entry\": {\n \"is_logged\": true,\n \"duration\": 600,\n \"note\": \"Updated Note\",\n \"started_at\": \"2016-08-16T18:03:28.000Z\",\n \"timer\": {\n \"id\": \"2936\"\n },\n \"client_id\": {{clientId}},\n \"project_id\": {{projectId}}\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/timetracking/business/{{businessId}}/time_entries/{{timeEntryId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"timetracking",
"business",
"{{businessId}}",
"time_entries",
"{{timeEntryId}}"
]
}
},
"response": [
{
"name": "Update a Time Entry",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"time_entry\": {\n \"is_logged\": true,\n \"duration\": 600,\n \"note\": \"Updated Note\",\n \"started_at\": \"2016-08-16T18:03:28.000Z\",\n \"timer\": {\n \"id\": \"2936\"\n },\n \"client_id\": {{clientId}},\n \"project_id\": {{projectId}}\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/timetracking/business/{{businessId}}/time_entries/{{timeEntryId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"timetracking",
"business",
"{{businessId}}",
"time_entries",
"{{timeEntryId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Content-Type",
"value": "application/vnd.api+json"
},
{
"key": "X-Version",
"value": "1904.25.0"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNFlkPXT1dVkBASktLBEIORhAHUw0VDw5dbFUKFRBOExtWSAEYAlRVVlcIUghUCgACBAFUCE0DVAdORgQBUVFaCQoEVQVVDwVWBFYTGlUDChAHbQ=="
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Tue, 24 Apr 2018 18:45:14 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Via",
"value": "1.1 varnish"
},
{
"key": "Content-Length",
"value": "450"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Date",
"value": "Wed, 24 Apr 2019 18:45:14 GMT"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "X-Served-By",
"value": "cache-mdw17369-MDW"
},
{
"key": "X-Cache",
"value": "MISS"
},
{
"key": "X-Cache-Hits",
"value": "0"
},
{
"key": "Country",
"value": "CA"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains; preload"
}
],
"cookie": [
],
"body": "{\n \"time_entry\": {\n \"id\": 47902064,\n \"identity_id\": 1882548,\n \"timer\": null,\n \"is_logged\": true,\n \"started_at\": \"2016-08-16T18:03:28Z\",\n \"created_at\": \"2019-04-24T18:44:50Z\",\n \"duration\": 600,\n \"client_id\": 31006,\n \"project_id\": 2989082,\n \"pending_client\": null,\n \"pending_project\": null,\n \"pending_task\": null,\n \"task_id\": null,\n \"service_id\": null,\n \"note\": \"Updated Note\",\n \"active\": true,\n \"billable\": false,\n \"billed\": false,\n \"internal\": false,\n \"retainer_id\": null\n }\n}"
}
]
}