Chilkat Online Tools

Node.js / New FreshBooks / List Entries

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

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

    var http = new chilkat.Http();
    var success;

    // Adds the "Authorization: Bearer <access_token>" header.
    http.AuthToken = "<access_token>";

    var sbResponseBody = new chilkat.StringBuilder();
    success = http.QuickGetSb("https://api.freshbooks.com/timetracking/business/{{businessId}}/time_entries",sbResponseBody);
    if (success == false) {
        console.log(http.LastErrorText);
        return;
    }

    var jResp = new chilkat.JsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.EmitCompact = false;

    console.log("Response Body:");
    console.log(jResp.Emit());

    var respStatusCode = http.LastStatus;
    console.log("Response Status Code = " + respStatusCode);
    if (respStatusCode >= 400) {
        console.log("Response Header:");
        console.log(http.LastHeader);
        console.log("Failed.");
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "meta": {
    //     "total_logged": 54000,
    //     "total_unbilled": 0,
    //     "total": 7,
    //     "per_page": 7,
    //     "page": 1,
    //     "pages": 1
    //   },
    //   "time_entries": [
    //     {
    //       "id": 47634496,
    //       "identity_id": 1882548,
    //       "timer": null,
    //       "is_logged": true,
    //       "started_at": "2016-08-16T20:00:00Z",
    //       "created_at": "2019-04-18T15:16:32Z",
    //       "duration": 7200,
    //       "client_id": 31006,
    //       "project_id": 2976412,
    //       "pending_client": null,
    //       "pending_project": null,
    //       "pending_task": null,
    //       "task_id": null,
    //       "service_id": null,
    //       "note": "Stuff",
    //       "active": true,
    //       "billable": false,
    //       "billed": false,
    //       "internal": false,
    //       "retainer_id": null
    //     },
    //     {
    //       "id": 47632920,
    //       "identity_id": 1882548,
    //       "timer": null,
    //       "is_logged": true,
    //       "started_at": "2016-08-16T20:00:00Z",
    //       "created_at": "2019-04-18T14:58:17Z",
    //       "duration": 7200,
    //       "client_id": 31006,
    //       "project_id": 2976412,
    //       "pending_client": null,
    //       "pending_project": null,
    //       "pending_task": null,
    //       "task_id": null,
    //       "service_id": null,
    //       "note": "Stuff",
    //       "active": true,
    //       "billable": false,
    //       "billed": false,
    //       "internal": false,
    //       "retainer_id": null
    //     },
    //     {
    //       "id": 47632874,
    //       "identity_id": 1882548,
    //       "timer": null,
    //       "is_logged": true,
    //       "started_at": "2016-08-16T20:00:00Z",
    //       "created_at": "2019-04-18T14:57:34Z",
    //       "duration": 7200,
    //       "client_id": 31006,
    //       "project_id": 2976412,
    //       "pending_client": null,
    //       "pending_project": null,
    //       "pending_task": null,
    //       "task_id": null,
    //       "service_id": null,
    //       "note": "Stuff",
    //       "active": true,
    //       "billable": false,
    //       "billed": false,
    //       "internal": false,
    //       "retainer_id": null
    //     },
    //     {
    //       "id": 47630476,
    //       "identity_id": 1882548,
    //       "timer": null,
    //       "is_logged": true,
    //       "started_at": "2019-04-15T04:00:00Z",
    //       "created_at": "2019-04-18T14:11:34Z",
    //       "duration": 7200,
    //       "client_id": 31006,
    //       "project_id": 2976412,
    //       "pending_client": null,
    //       "pending_project": null,
    //       "pending_task": null,
    //       "task_id": null,
    //       "service_id": 3575792,
    //       "note": null,
    //       "active": true,
    //       "billable": false,
    //       "billed": false,
    //       "internal": false,
    //       "retainer_id": null
    //     },
    //     {
    //       "id": 47630478,
    //       "identity_id": 1882548,
    //       "timer": null,
    //       "is_logged": true,
    //       "started_at": "2019-04-17T04:00:00Z",
    //       "created_at": "2019-04-18T14:11:34Z",
    //       "duration": 7200,
    //       "client_id": 31006,
    //       "project_id": 2976412,
    //       "pending_client": null,
    //       "pending_project": null,
    //       "pending_task": null,
    //       "task_id": null,
    //       "service_id": 3575792,
    //       "note": null,
    //       "active": true,
    //       "billable": false,
    //       "billed": false,
    //       "internal": false,
    //       "retainer_id": null
    //     },
    //     {
    //       "id": 47630480,
    //       "identity_id": 1882548,
    //       "timer": null,
    //       "is_logged": true,
    //       "started_at": "2019-04-18T04:00:00Z",
    //       "created_at": "2019-04-18T14:11:34Z",
    //       "duration": 7200,
    //       "client_id": 31006,
    //       "project_id": 2976412,
    //       "pending_client": null,
    //       "pending_project": null,
    //       "pending_task": null,
    //       "task_id": null,
    //       "service_id": 3575792,
    //       "note": null,
    //       "active": true,
    //       "billable": false,
    //       "billed": false,
    //       "internal": false,
    //       "retainer_id": null
    //     },
    //     {
    //       "id": 47630482,
    //       "identity_id": 1882548,
    //       "timer": null,
    //       "is_logged": true,
    //       "started_at": "2019-04-19T04:00:00Z",
    //       "created_at": "2019-04-18T14:11:34Z",
    //       "duration": 10800,
    //       "client_id": 31006,
    //       "project_id": 2976412,
    //       "pending_client": null,
    //       "pending_project": null,
    //       "pending_task": null,
    //       "task_id": null,
    //       "service_id": 3575792,
    //       "note": null,
    //       "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

    var id;
    var identity_id;
    var timer;
    var is_logged;
    var started_at;
    var created_at;
    var duration;
    var client_id;
    var project_id;
    var pending_client;
    var pending_project;
    var pending_task;
    var task_id;
    var service_id;
    var note;
    var active;
    var billable;
    var billed;
    var internal;
    var retainer_id;

    var Total_logged = jResp.IntOf("meta.total_logged");
    var Total_unbilled = jResp.IntOf("meta.total_unbilled");
    var Total = jResp.IntOf("meta.total");
    var Per_page = jResp.IntOf("meta.per_page");
    var Page = jResp.IntOf("meta.page");
    var Pages = jResp.IntOf("meta.pages");
    var i = 0;
    var count_i = jResp.SizeOfArray("time_entries");
    while (i < count_i) {
        jResp.I = i;
        id = jResp.IntOf("time_entries[i].id");
        identity_id = jResp.IntOf("time_entries[i].identity_id");
        timer = jResp.StringOf("time_entries[i].timer");
        is_logged = jResp.BoolOf("time_entries[i].is_logged");
        started_at = jResp.StringOf("time_entries[i].started_at");
        created_at = jResp.StringOf("time_entries[i].created_at");
        duration = jResp.IntOf("time_entries[i].duration");
        client_id = jResp.IntOf("time_entries[i].client_id");
        project_id = jResp.IntOf("time_entries[i].project_id");
        pending_client = jResp.StringOf("time_entries[i].pending_client");
        pending_project = jResp.StringOf("time_entries[i].pending_project");
        pending_task = jResp.StringOf("time_entries[i].pending_task");
        task_id = jResp.StringOf("time_entries[i].task_id");
        service_id = jResp.StringOf("time_entries[i].service_id");
        note = jResp.StringOf("time_entries[i].note");
        active = jResp.BoolOf("time_entries[i].active");
        billable = jResp.BoolOf("time_entries[i].billable");
        billed = jResp.BoolOf("time_entries[i].billed");
        internal = jResp.BoolOf("time_entries[i].internal");
        retainer_id = jResp.StringOf("time_entries[i].retainer_id");
        i = i+1;
    }


}

chilkatExample();

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://api.freshbooks.com/timetracking/business/{{businessId}}/time_entries

Postman Collection Item JSON

{
  "name": "List Entries",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.freshbooks.com/timetracking/business/{{businessId}}/time_entries",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "timetracking",
        "business",
        "{{businessId}}",
        "time_entries"
      ]
    }
  },
  "response": [
    {
      "name": "List Entries",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.freshbooks.com/timetracking/business/{{businessId}}/time_entries",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "timetracking",
            "business",
            "{{businessId}}",
            "time_entries"
          ]
        }
      },
      "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": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNFlkPXT1dVkBAWgBKT0MEQA0RRFQEXBdRXlU7BAxDQ14DFxMaA05WTVIHVwhXAQwFAQpVAFgAUwJTSBsGTUQGAQYJUFQEUgdRBQcBUAFURE8EUQ5LB2U="
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Tue, 24 Apr 2018 18:42:32 GMT"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Via",
          "value": "1.1 google"
        },
        {
          "key": "Via",
          "value": "1.1 varnish"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Age",
          "value": "0"
        },
        {
          "key": "Age",
          "value": "0"
        },
        {
          "key": "Content-Length",
          "value": "3133"
        },
        {
          "key": "Date",
          "value": "Wed, 24 Apr 2019 18:42:32 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    \"meta\": {\n        \"total_logged\": 54000,\n        \"total_unbilled\": 0,\n        \"total\": 7,\n        \"per_page\": 7,\n        \"page\": 1,\n        \"pages\": 1\n    },\n    \"time_entries\": [\n        {\n            \"id\": 47634496,\n            \"identity_id\": 1882548,\n            \"timer\": null,\n            \"is_logged\": true,\n            \"started_at\": \"2016-08-16T20:00:00Z\",\n            \"created_at\": \"2019-04-18T15:16:32Z\",\n            \"duration\": 7200,\n            \"client_id\": 31006,\n            \"project_id\": 2976412,\n            \"pending_client\": null,\n            \"pending_project\": null,\n            \"pending_task\": null,\n            \"task_id\": null,\n            \"service_id\": null,\n            \"note\": \"Stuff\",\n            \"active\": true,\n            \"billable\": false,\n            \"billed\": false,\n            \"internal\": false,\n            \"retainer_id\": null\n        },\n        {\n            \"id\": 47632920,\n            \"identity_id\": 1882548,\n            \"timer\": null,\n            \"is_logged\": true,\n            \"started_at\": \"2016-08-16T20:00:00Z\",\n            \"created_at\": \"2019-04-18T14:58:17Z\",\n            \"duration\": 7200,\n            \"client_id\": 31006,\n            \"project_id\": 2976412,\n            \"pending_client\": null,\n            \"pending_project\": null,\n            \"pending_task\": null,\n            \"task_id\": null,\n            \"service_id\": null,\n            \"note\": \"Stuff\",\n            \"active\": true,\n            \"billable\": false,\n            \"billed\": false,\n            \"internal\": false,\n            \"retainer_id\": null\n        },\n        {\n            \"id\": 47632874,\n            \"identity_id\": 1882548,\n            \"timer\": null,\n            \"is_logged\": true,\n            \"started_at\": \"2016-08-16T20:00:00Z\",\n            \"created_at\": \"2019-04-18T14:57:34Z\",\n            \"duration\": 7200,\n            \"client_id\": 31006,\n            \"project_id\": 2976412,\n            \"pending_client\": null,\n            \"pending_project\": null,\n            \"pending_task\": null,\n            \"task_id\": null,\n            \"service_id\": null,\n            \"note\": \"Stuff\",\n            \"active\": true,\n            \"billable\": false,\n            \"billed\": false,\n            \"internal\": false,\n            \"retainer_id\": null\n        },\n        {\n            \"id\": 47630476,\n            \"identity_id\": 1882548,\n            \"timer\": null,\n            \"is_logged\": true,\n            \"started_at\": \"2019-04-15T04:00:00Z\",\n            \"created_at\": \"2019-04-18T14:11:34Z\",\n            \"duration\": 7200,\n            \"client_id\": 31006,\n            \"project_id\": 2976412,\n            \"pending_client\": null,\n            \"pending_project\": null,\n            \"pending_task\": null,\n            \"task_id\": null,\n            \"service_id\": 3575792,\n            \"note\": null,\n            \"active\": true,\n            \"billable\": false,\n            \"billed\": false,\n            \"internal\": false,\n            \"retainer_id\": null\n        },\n        {\n            \"id\": 47630478,\n            \"identity_id\": 1882548,\n            \"timer\": null,\n            \"is_logged\": true,\n            \"started_at\": \"2019-04-17T04:00:00Z\",\n            \"created_at\": \"2019-04-18T14:11:34Z\",\n            \"duration\": 7200,\n            \"client_id\": 31006,\n            \"project_id\": 2976412,\n            \"pending_client\": null,\n            \"pending_project\": null,\n            \"pending_task\": null,\n            \"task_id\": null,\n            \"service_id\": 3575792,\n            \"note\": null,\n            \"active\": true,\n            \"billable\": false,\n            \"billed\": false,\n            \"internal\": false,\n            \"retainer_id\": null\n        },\n        {\n            \"id\": 47630480,\n            \"identity_id\": 1882548,\n            \"timer\": null,\n            \"is_logged\": true,\n            \"started_at\": \"2019-04-18T04:00:00Z\",\n            \"created_at\": \"2019-04-18T14:11:34Z\",\n            \"duration\": 7200,\n            \"client_id\": 31006,\n            \"project_id\": 2976412,\n            \"pending_client\": null,\n            \"pending_project\": null,\n            \"pending_task\": null,\n            \"task_id\": null,\n            \"service_id\": 3575792,\n            \"note\": null,\n            \"active\": true,\n            \"billable\": false,\n            \"billed\": false,\n            \"internal\": false,\n            \"retainer_id\": null\n        },\n        {\n            \"id\": 47630482,\n            \"identity_id\": 1882548,\n            \"timer\": null,\n            \"is_logged\": true,\n            \"started_at\": \"2019-04-19T04:00:00Z\",\n            \"created_at\": \"2019-04-18T14:11:34Z\",\n            \"duration\": 10800,\n            \"client_id\": 31006,\n            \"project_id\": 2976412,\n            \"pending_client\": null,\n            \"pending_project\": null,\n            \"pending_task\": null,\n            \"task_id\": null,\n            \"service_id\": 3575792,\n            \"note\": null,\n            \"active\": true,\n            \"billable\": false,\n            \"billed\": false,\n            \"internal\": false,\n            \"retainer_id\": null\n        }\n    ]\n}"
    }
  ]
}