SQL Server / New FreshBooks / List Projects
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.freshbooks.com/projects/business/{{businessId}}/projects', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
-- 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
DECLARE @id int
DECLARE @title nvarchar(4000)
DECLARE @description nvarchar(4000)
DECLARE @due_date nvarchar(4000)
DECLARE @client_id int
DECLARE @internal int
DECLARE @budget nvarchar(4000)
DECLARE @fixed_price nvarchar(4000)
DECLARE @rate nvarchar(4000)
DECLARE @billing_method nvarchar(4000)
DECLARE @project_type nvarchar(4000)
DECLARE @active int
DECLARE @complete int
DECLARE @sample int
DECLARE @created_at nvarchar(4000)
DECLARE @updated_at nvarchar(4000)
DECLARE @logged_duration nvarchar(4000)
DECLARE @billed_amount nvarchar(4000)
DECLARE @billed_status nvarchar(4000)
DECLARE @group_id int
DECLARE @j int
DECLARE @count_j int
DECLARE @business_id int
DECLARE @name nvarchar(4000)
DECLARE @billable int
DECLARE @vis_state int
DECLARE @Total int
EXEC sp_OAMethod @jResp, 'IntOf', @Total OUT, 'meta.total'
DECLARE @Per_page int
EXEC sp_OAMethod @jResp, 'IntOf', @Per_page OUT, 'meta.per_page'
DECLARE @Page int
EXEC sp_OAMethod @jResp, 'IntOf', @Page OUT, 'meta.page'
DECLARE @Pages int
EXEC sp_OAMethod @jResp, 'IntOf', @Pages OUT, 'meta.pages'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'meta.sort'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'projects'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'IntOf', @id OUT, 'projects[i].id'
EXEC sp_OAMethod @jResp, 'StringOf', @title OUT, 'projects[i].title'
EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'projects[i].description'
EXEC sp_OAMethod @jResp, 'StringOf', @due_date OUT, 'projects[i].due_date'
EXEC sp_OAMethod @jResp, 'IntOf', @client_id OUT, 'projects[i].client_id'
EXEC sp_OAMethod @jResp, 'BoolOf', @internal OUT, 'projects[i].internal'
EXEC sp_OAMethod @jResp, 'StringOf', @budget OUT, 'projects[i].budget'
EXEC sp_OAMethod @jResp, 'StringOf', @fixed_price OUT, 'projects[i].fixed_price'
EXEC sp_OAMethod @jResp, 'StringOf', @rate OUT, 'projects[i].rate'
EXEC sp_OAMethod @jResp, 'StringOf', @billing_method OUT, 'projects[i].billing_method'
EXEC sp_OAMethod @jResp, 'StringOf', @project_type OUT, 'projects[i].project_type'
EXEC sp_OAMethod @jResp, 'BoolOf', @active OUT, 'projects[i].active'
EXEC sp_OAMethod @jResp, 'BoolOf', @complete OUT, 'projects[i].complete'
EXEC sp_OAMethod @jResp, 'BoolOf', @sample OUT, 'projects[i].sample'
EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'projects[i].created_at'
EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'projects[i].updated_at'
EXEC sp_OAMethod @jResp, 'StringOf', @logged_duration OUT, 'projects[i].logged_duration'
EXEC sp_OAMethod @jResp, 'StringOf', @billed_amount OUT, 'projects[i].billed_amount'
EXEC sp_OAMethod @jResp, 'StringOf', @billed_status OUT, 'projects[i].billed_status'
EXEC sp_OAMethod @jResp, 'IntOf', @group_id OUT, 'projects[i].group_id'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'projects[i].services'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'IntOf', @business_id OUT, 'projects[i].services[j].business_id'
EXEC sp_OAMethod @jResp, 'IntOf', @id OUT, 'projects[i].services[j].id'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'projects[i].services[j].name'
EXEC sp_OAMethod @jResp, 'BoolOf', @billable OUT, 'projects[i].services[j].billable'
EXEC sp_OAMethod @jResp, 'IntOf', @vis_state OUT, 'projects[i].services[j].vis_state'
SELECT @j = @j + 1
END
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
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}"
}
]
}