Chilkat Online Tools

PowerBuilder / New FreshBooks / List Projects

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
integer li_Id
string ls_Title
string ls_Description
string ls_Due_date
integer li_Client_id
integer li_Internal
string ls_Budget
string ls_Fixed_price
string ls_Rate
string ls_Billing_method
string ls_Project_type
integer li_Active
integer li_Complete
integer li_Sample
string ls_Created_at
string ls_Updated_at
string ls_Logged_duration
string ls_Billed_amount
string ls_Billed_status
integer li_Group_id
integer j
integer li_Count_j
integer li_Business_id
string ls_Name
integer li_Billable
integer li_Vis_state
integer li_Total
integer li_Per_page
integer li_Page
integer li_Pages
integer i
integer li_Count_i

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://api.freshbooks.com/projects/business/{{businessId}}/projects",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

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

// {
//   "meta": {
//     "sort": [
//     ],
//     "total": 5,
//     "per_page": 30,
//     "page": 1,
//     "pages": 1
//   },
//   "projects": [
//     {
//       "id": 2980878,
//       "title": "K2 Hiking Guide",
//       "description": null,
//       "due_date": "2019-04-20",
//       "client_id": 31006,
//       "internal": false,
//       "budget": null,
//       "fixed_price": "2000.00",
//       "rate": null,
//       "billing_method": null,
//       "project_type": "fixed_price",
//       "active": true,
//       "complete": false,
//       "sample": false,
//       "created_at": "2019-04-19T18:25:00",
//       "updated_at": "2019-04-19T19:50:26",
//       "logged_duration": null,
//       "services": [
//       ],
//       "billed_amount": "0.00",
//       "billed_status": "unbilled",
//       "group_id": 4951020
//     },
//     {
//       "id": 2980874,
//       "title": "Applachian Hiking Guide",
//       "description": null,
//       "due_date": "2019-05-20",
//       "client_id": 31006,
//       "internal": false,
//       "budget": null,
//       "fixed_price": "1000.00",
//       "rate": null,
//       "billing_method": null,
//       "project_type": "fixed_price",
//       "active": true,
//       "complete": false,
//       "sample": false,
//       "created_at": "2019-04-19T18:22:43",
//       "updated_at": "2019-04-19T18:22:43",
//       "logged_duration": null,
//       "services": [
//       ],
//       "billed_amount": "0.00",
//       "billed_status": "unbilled",
//       "group_id": 4951012
//     },
//     {
//       "id": 2980872,
//       "title": "Applachian Hiking Guide",
//       "description": null,
//       "due_date": "2019-05-20",
//       "client_id": 31006,
//       "internal": false,
//       "budget": null,
//       "fixed_price": "1000.00",
//       "rate": null,
//       "billing_method": null,
//       "project_type": "fixed_price",
//       "active": true,
//       "complete": false,
//       "sample": false,
//       "created_at": "2019-04-19T18:22:06",
//       "updated_at": "2019-04-19T18:22:06",
//       "logged_duration": null,
//       "services": [
//       ],
//       "billed_amount": "0.00",
//       "billed_status": "unbilled",
//       "group_id": 4951006
//     },
//     {
//       "id": 2980870,
//       "title": "Hiking Guide",
//       "description": null,
//       "due_date": "2019-05-20",
//       "client_id": 31006,
//       "internal": false,
//       "budget": null,
//       "fixed_price": "500.00",
//       "rate": null,
//       "billing_method": null,
//       "project_type": "fixed_price",
//       "active": true,
//       "complete": false,
//       "sample": false,
//       "created_at": "2019-04-19T18:21:11",
//       "updated_at": "2019-04-19T18:21:11",
//       "logged_duration": null,
//       "services": [
//       ],
//       "billed_amount": "0.00",
//       "billed_status": "unbilled",
//       "group_id": 4951004
//     },
//     {
//       "id": 2976412,
//       "title": "Very Custom Computer thing",
//       "description": null,
//       "due_date": null,
//       "client_id": 31006,
//       "internal": false,
//       "budget": null,
//       "fixed_price": null,
//       "rate": null,
//       "billing_method": "project_rate",
//       "project_type": "fixed_price",
//       "active": true,
//       "complete": false,
//       "sample": false,
//       "created_at": "2019-04-18T13:43:31",
//       "updated_at": "2019-04-18T13:43:31",
//       "logged_duration": null,
//       "services": [
//         {
//           "business_id": 1966214,
//           "id": 3575792,
//           "name": "Computer Hardware",
//           "billable": true,
//           "vis_state": 0
//         }
//       ],
//       "billed_amount": "0.00",
//       "billed_status": "unbilled",
//       "group_id": 4942784
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

li_Total = loo_JResp.IntOf("meta.total")
li_Per_page = loo_JResp.IntOf("meta.per_page")
li_Page = loo_JResp.IntOf("meta.page")
li_Pages = loo_JResp.IntOf("meta.pages")
i = 0
li_Count_i = loo_JResp.SizeOfArray("meta.sort")
do while i < li_Count_i
    loo_JResp.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("projects")
do while i < li_Count_i
    loo_JResp.I = i
    li_Id = loo_JResp.IntOf("projects[i].id")
    ls_Title = loo_JResp.StringOf("projects[i].title")
    ls_Description = loo_JResp.StringOf("projects[i].description")
    ls_Due_date = loo_JResp.StringOf("projects[i].due_date")
    li_Client_id = loo_JResp.IntOf("projects[i].client_id")
    li_Internal = loo_JResp.BoolOf("projects[i].internal")
    ls_Budget = loo_JResp.StringOf("projects[i].budget")
    ls_Fixed_price = loo_JResp.StringOf("projects[i].fixed_price")
    ls_Rate = loo_JResp.StringOf("projects[i].rate")
    ls_Billing_method = loo_JResp.StringOf("projects[i].billing_method")
    ls_Project_type = loo_JResp.StringOf("projects[i].project_type")
    li_Active = loo_JResp.BoolOf("projects[i].active")
    li_Complete = loo_JResp.BoolOf("projects[i].complete")
    li_Sample = loo_JResp.BoolOf("projects[i].sample")
    ls_Created_at = loo_JResp.StringOf("projects[i].created_at")
    ls_Updated_at = loo_JResp.StringOf("projects[i].updated_at")
    ls_Logged_duration = loo_JResp.StringOf("projects[i].logged_duration")
    ls_Billed_amount = loo_JResp.StringOf("projects[i].billed_amount")
    ls_Billed_status = loo_JResp.StringOf("projects[i].billed_status")
    li_Group_id = loo_JResp.IntOf("projects[i].group_id")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("projects[i].services")
    do while j < li_Count_j
        loo_JResp.J = j
        li_Business_id = loo_JResp.IntOf("projects[i].services[j].business_id")
        li_Id = loo_JResp.IntOf("projects[i].services[j].id")
        ls_Name = loo_JResp.StringOf("projects[i].services[j].name")
        li_Billable = loo_JResp.BoolOf("projects[i].services[j].billable")
        li_Vis_state = loo_JResp.IntOf("projects[i].services[j].vis_state")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

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

Postman Collection Item JSON

{
  "name": "List Projects",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "let jsonData = JSON.parse(responseBody);",
          "pm.environment.set(\"projectId\", jsonData.projects[0].id);"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.freshbooks.com/projects/business/{{businessId}}/projects",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "projects",
        "business",
        "{{businessId}}",
        "projects"
      ]
    },
    "description": "Remember to remove `Content-Type` headers when making a GET call on projects and time-tracking."
  },
  "response": [
    {
      "name": "List Projects",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.freshbooks.com/projects/business/{{businessId}}/projects",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "projects",
            "business",
            "{{businessId}}",
            "projects"
          ]
        }
      },
      "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.24.0"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEkINUgdbTEccQQBKDkQTUAdeRkUODAZbR0NGTVIbARlWUgYBA1FfVVADUA5SDAEMHh5UFUMAVVdUUA9VWAUCD1IIUlhQFR1RBwhCU24="
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Tue, 24 Apr 2018 18:24:44 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": "2629"
        },
        {
          "key": "Date",
          "value": "Wed, 24 Apr 2019 18:24:44 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        \"sort\": [],\n        \"total\": 5,\n        \"per_page\": 30,\n        \"page\": 1,\n        \"pages\": 1\n    },\n    \"projects\": [\n        {\n            \"id\": 2980878,\n            \"title\": \"K2 Hiking Guide\",\n            \"description\": null,\n            \"due_date\": \"2019-04-20\",\n            \"client_id\": 31006,\n            \"internal\": false,\n            \"budget\": null,\n            \"fixed_price\": \"2000.00\",\n            \"rate\": null,\n            \"billing_method\": null,\n            \"project_type\": \"fixed_price\",\n            \"active\": true,\n            \"complete\": false,\n            \"sample\": false,\n            \"created_at\": \"2019-04-19T18:25:00\",\n            \"updated_at\": \"2019-04-19T19:50:26\",\n            \"logged_duration\": null,\n            \"services\": [],\n            \"billed_amount\": \"0.00\",\n            \"billed_status\": \"unbilled\",\n            \"group_id\": 4951020\n        },\n        {\n            \"id\": 2980874,\n            \"title\": \"Applachian Hiking Guide\",\n            \"description\": null,\n            \"due_date\": \"2019-05-20\",\n            \"client_id\": 31006,\n            \"internal\": false,\n            \"budget\": null,\n            \"fixed_price\": \"1000.00\",\n            \"rate\": null,\n            \"billing_method\": null,\n            \"project_type\": \"fixed_price\",\n            \"active\": true,\n            \"complete\": false,\n            \"sample\": false,\n            \"created_at\": \"2019-04-19T18:22:43\",\n            \"updated_at\": \"2019-04-19T18:22:43\",\n            \"logged_duration\": null,\n            \"services\": [],\n            \"billed_amount\": \"0.00\",\n            \"billed_status\": \"unbilled\",\n            \"group_id\": 4951012\n        },\n        {\n            \"id\": 2980872,\n            \"title\": \"Applachian Hiking Guide\",\n            \"description\": null,\n            \"due_date\": \"2019-05-20\",\n            \"client_id\": 31006,\n            \"internal\": false,\n            \"budget\": null,\n            \"fixed_price\": \"1000.00\",\n            \"rate\": null,\n            \"billing_method\": null,\n            \"project_type\": \"fixed_price\",\n            \"active\": true,\n            \"complete\": false,\n            \"sample\": false,\n            \"created_at\": \"2019-04-19T18:22:06\",\n            \"updated_at\": \"2019-04-19T18:22:06\",\n            \"logged_duration\": null,\n            \"services\": [],\n            \"billed_amount\": \"0.00\",\n            \"billed_status\": \"unbilled\",\n            \"group_id\": 4951006\n        },\n        {\n            \"id\": 2980870,\n            \"title\": \"Hiking Guide\",\n            \"description\": null,\n            \"due_date\": \"2019-05-20\",\n            \"client_id\": 31006,\n            \"internal\": false,\n            \"budget\": null,\n            \"fixed_price\": \"500.00\",\n            \"rate\": null,\n            \"billing_method\": null,\n            \"project_type\": \"fixed_price\",\n            \"active\": true,\n            \"complete\": false,\n            \"sample\": false,\n            \"created_at\": \"2019-04-19T18:21:11\",\n            \"updated_at\": \"2019-04-19T18:21:11\",\n            \"logged_duration\": null,\n            \"services\": [],\n            \"billed_amount\": \"0.00\",\n            \"billed_status\": \"unbilled\",\n            \"group_id\": 4951004\n        },\n        {\n            \"id\": 2976412,\n            \"title\": \"Very Custom Computer thing\",\n            \"description\": null,\n            \"due_date\": null,\n            \"client_id\": 31006,\n            \"internal\": false,\n            \"budget\": null,\n            \"fixed_price\": null,\n            \"rate\": null,\n            \"billing_method\": \"project_rate\",\n            \"project_type\": \"fixed_price\",\n            \"active\": true,\n            \"complete\": false,\n            \"sample\": false,\n            \"created_at\": \"2019-04-18T13:43:31\",\n            \"updated_at\": \"2019-04-18T13:43:31\",\n            \"logged_duration\": null,\n            \"services\": [\n                {\n                    \"business_id\": 1966214,\n                    \"id\": 3575792,\n                    \"name\": \"Computer Hardware\",\n                    \"billable\": true,\n                    \"vis_state\": 0\n                }\n            ],\n            \"billed_amount\": \"0.00\",\n            \"billed_status\": \"unbilled\",\n            \"group_id\": 4942784\n        }\n    ]\n}"
    }
  ]
}