SQL Server / New FreshBooks / Undelete Retainer
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
DECLARE @iTmp0 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
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "retainer": {
-- "active": true
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'retainer.active', 1
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}', @sbRequestBody, 'utf-8', 'application/json', 0, 0
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
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 @resp, 'GetBodySb', @success OUT, @sbResponseBody
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 @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "retainer": {
-- "id": 2248,
-- "business_id": 1966214,
-- "system_id": 4236410,
-- "invoice_profile_id": null,
-- "client_user_id": 75162,
-- "start_date": "2019-06-03",
-- "next_period_start_date": "2019-07-03",
-- "fee": "20.00",
-- "excess_rate": "700.00",
-- "budgeted_time": 180000,
-- "active": true,
-- "created_at": "2019-06-03T15:42:49",
-- "updated_at": "2019-06-03T18:25:02"
-- }
-- }
-- 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
EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'retainer.id'
DECLARE @Business_id int
EXEC sp_OAMethod @jResp, 'IntOf', @Business_id OUT, 'retainer.business_id'
DECLARE @System_id int
EXEC sp_OAMethod @jResp, 'IntOf', @System_id OUT, 'retainer.system_id'
DECLARE @Invoice_profile_id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Invoice_profile_id OUT, 'retainer.invoice_profile_id'
DECLARE @Client_user_id int
EXEC sp_OAMethod @jResp, 'IntOf', @Client_user_id OUT, 'retainer.client_user_id'
DECLARE @Start_date nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Start_date OUT, 'retainer.start_date'
DECLARE @Next_period_start_date nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Next_period_start_date OUT, 'retainer.next_period_start_date'
DECLARE @Fee nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Fee OUT, 'retainer.fee'
DECLARE @Excess_rate nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Excess_rate OUT, 'retainer.excess_rate'
DECLARE @Budgeted_time int
EXEC sp_OAMethod @jResp, 'IntOf', @Budgeted_time OUT, 'retainer.budgeted_time'
DECLARE @Active int
EXEC sp_OAMethod @jResp, 'BoolOf', @Active OUT, 'retainer.active'
DECLARE @Created_at nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Created_at OUT, 'retainer.created_at'
DECLARE @Updated_at nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Updated_at OUT, 'retainer.updated_at'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '{
"retainer": {
"active": true
}
}'
https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}
Postman Collection Item JSON
{
"name": "Undelete Retainer",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"retainer\": {\n \"active\": true\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"comments",
"business",
"{{businessId}}",
"retainer",
"{{retainerId}}"
]
},
"description": "A retainer is deleted by changing the active status to \"false\". It can be undeleted by changing active status back to true."
},
"response": [
{
"name": "Undelete Retainer Success",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"retainer\": {\n \"active\": true\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"comments",
"business",
"{{businessId}}",
"retainer",
"{{retainerId}}"
]
}
},
"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": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEFUWWQtWXUYcQQBKDkQTUAdeRFIVBwpWVkJGTVIbARlXVAUHAFNfUFUAUA5bDw8BBh9QCU0TUgpbBQQEBABVDwRRVwBaBRMbAAVdRVY/"
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "0"
},
{
"key": "X-RateLimit-Reset",
"value": "1559586355"
},
{
"key": "Retry-After",
"value": "52"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Sun, 03 Jun 2018 18:25:02 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Via",
"value": "1.1 varnish"
},
{
"key": "Content-Length",
"value": "349"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Date",
"value": "Mon, 03 Jun 2019 18:25:02 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 \"retainer\": {\n \"id\": 2248,\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-07-03\",\n \"fee\": \"20.00\",\n \"excess_rate\": \"700.00\",\n \"budgeted_time\": 180000,\n \"active\": true,\n \"created_at\": \"2019-06-03T15:42:49\",\n \"updated_at\": \"2019-06-03T18:25:02\"\n }\n}"
}
]
}