SQL Server / New FreshBooks / Get all retainers
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/comments/business/{{businessId}}/retainers', @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)
-- {
-- "retainers": [
-- {
-- "id": 2248,
-- "business_id": 1966214,
-- "system_id": 4236410,
-- "invoice_profile_id": null,
-- "client_user_id": 32046,
-- "start_date": "2019-06-03",
-- "next_period_start_date": "2019-06-03",
-- "fee": "500.00",
-- "excess_rate": "100.00",
-- "budgeted_time": 144000,
-- "active": true,
-- "created_at": "2019-06-03T15:42:49",
-- "updated_at": "2019-06-03T15:42:49"
-- },
-- {
-- "id": 2272,
-- "business_id": 1966214,
-- "system_id": 4236410,
-- "invoice_profile_id": null,
-- "client_user_id": 75162,
-- "start_date": "2019-06-03",
-- "next_period_start_date": "2019-06-03",
-- "fee": "20.00",
-- "excess_rate": "500.00",
-- "budgeted_time": 180000,
-- "active": true,
-- "created_at": "2019-06-03T18:08:30",
-- "updated_at": "2019-06-03T18:08:30"
-- },
-- {
-- "id": 2274,
-- "business_id": 1966214,
-- "system_id": 4236410,
-- "invoice_profile_id": null,
-- "client_user_id": 32040,
-- "start_date": "2019-06-05",
-- "next_period_start_date": "2019-06-03",
-- "fee": "600.00",
-- "excess_rate": "200.00",
-- "budgeted_time": 144000,
-- "active": true,
-- "created_at": "2019-06-03T18:11:26",
-- "updated_at": "2019-06-03T18:11:26"
-- }
-- ]
-- }
-- 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 @business_id int
DECLARE @system_id int
DECLARE @invoice_profile_id nvarchar(4000)
DECLARE @client_user_id int
DECLARE @start_date nvarchar(4000)
DECLARE @next_period_start_date nvarchar(4000)
DECLARE @fee nvarchar(4000)
DECLARE @excess_rate nvarchar(4000)
DECLARE @budgeted_time int
DECLARE @active int
DECLARE @created_at nvarchar(4000)
DECLARE @updated_at nvarchar(4000)
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'retainers'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'IntOf', @id OUT, 'retainers[i].id'
EXEC sp_OAMethod @jResp, 'IntOf', @business_id OUT, 'retainers[i].business_id'
EXEC sp_OAMethod @jResp, 'IntOf', @system_id OUT, 'retainers[i].system_id'
EXEC sp_OAMethod @jResp, 'StringOf', @invoice_profile_id OUT, 'retainers[i].invoice_profile_id'
EXEC sp_OAMethod @jResp, 'IntOf', @client_user_id OUT, 'retainers[i].client_user_id'
EXEC sp_OAMethod @jResp, 'StringOf', @start_date OUT, 'retainers[i].start_date'
EXEC sp_OAMethod @jResp, 'StringOf', @next_period_start_date OUT, 'retainers[i].next_period_start_date'
EXEC sp_OAMethod @jResp, 'StringOf', @fee OUT, 'retainers[i].fee'
EXEC sp_OAMethod @jResp, 'StringOf', @excess_rate OUT, 'retainers[i].excess_rate'
EXEC sp_OAMethod @jResp, 'IntOf', @budgeted_time OUT, 'retainers[i].budgeted_time'
EXEC sp_OAMethod @jResp, 'BoolOf', @active OUT, 'retainers[i].active'
EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'retainers[i].created_at'
EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'retainers[i].updated_at'
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/comments/business/{{businessId}}/retainers
Postman Collection Item JSON
{
"name": "Get all retainers",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainers",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"comments",
"business",
"{{businessId}}",
"retainers"
]
}
},
"response": [
{
"name": "Get all retainers Success",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainers",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"comments",
"business",
"{{businessId}}",
"retainers"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Content-Type",
"value": "application/vnd.api+json"
},
{
"key": "X-Version",
"value": "1905.33.0"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEFUWWQtWXUYcQQBKDkQTUAdeRFIVBwpWVkJGTVIbARlXUwYBClRXUVcEUwlbAA8HHh5UFUNSA1YBVQVVUgQFWVdRB1MEFR1RBwhCU24="
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "0"
},
{
"key": "X-RateLimit-Reset",
"value": "1559585847"
},
{
"key": "Retry-After",
"value": "59"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Sun, 03 Jun 2018 18:16:27 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": "1028"
},
{
"key": "Date",
"value": "Mon, 03 Jun 2019 18:16:27 GMT"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "X-Served-By",
"value": "cache-mdw17376-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 \"retainers\": [\n {\n \"id\": 2248,\n \"business_id\": 1966214,\n \"system_id\": 4236410,\n \"invoice_profile_id\": null,\n \"client_user_id\": 32046,\n \"start_date\": \"2019-06-03\",\n \"next_period_start_date\": \"2019-06-03\",\n \"fee\": \"500.00\",\n \"excess_rate\": \"100.00\",\n \"budgeted_time\": 144000,\n \"active\": true,\n \"created_at\": \"2019-06-03T15:42:49\",\n \"updated_at\": \"2019-06-03T15:42:49\"\n },\n {\n \"id\": 2272,\n \"business_id\": 1966214,\n \"system_id\": 4236410,\n \"invoice_profile_id\": null,\n \"client_user_id\": 75162,\n \"start_date\": \"2019-06-03\",\n \"next_period_start_date\": \"2019-06-03\",\n \"fee\": \"20.00\",\n \"excess_rate\": \"500.00\",\n \"budgeted_time\": 180000,\n \"active\": true,\n \"created_at\": \"2019-06-03T18:08:30\",\n \"updated_at\": \"2019-06-03T18:08:30\"\n },\n {\n \"id\": 2274,\n \"business_id\": 1966214,\n \"system_id\": 4236410,\n \"invoice_profile_id\": null,\n \"client_user_id\": 32040,\n \"start_date\": \"2019-06-05\",\n \"next_period_start_date\": \"2019-06-03\",\n \"fee\": \"600.00\",\n \"excess_rate\": \"200.00\",\n \"budgeted_time\": 144000,\n \"active\": true,\n \"created_at\": \"2019-06-03T18:11:26\",\n \"updated_at\": \"2019-06-03T18:11:26\"\n }\n ]\n}"
}
]
}