SQL Server / New FreshBooks / Get default invoice presentation styles
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/accounting/account/{{accountId}}/invoices/presentations', @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)
-- {
-- "response": {
-- "result": {
-- "presentation": {
-- "date_format": "mm/dd/yyyy",
-- "description_heading": null,
-- "hours_heading": null,
-- "image_banner_position_y": 0,
-- "image_banner_src": null,
-- "image_logo_src": "/uploads/images/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50Ijo0MjM2NDEwLCJvcmlnaW5hbF9maWxlbmFtZSI6InBpenphZG90bmV0LmpwZyIsImxlbmd0aCI6MTA2MDM3LCJmaWxlbmFtZSI6InVwbG9hZC0xM2UwMmRiYzI2ZWEyMmQzYTJmZmY3ZmZmYWUwZjZjMzE5MzUxMWQ4IiwiYnVja2V0IjoidXBsb2FkcyIsImtleSI6Iidkb2NzLSctNDIzNjQxMC91cGxvYWQtMTNlMDJkYmMyNmVhMjJkM2EyZmZmN2ZmZmFlMGY2YzMxOTM1MTFkOCJ9.d7YhBtzuxdiglt5d6eUVZc_dORsnOAJuDx1XvYj2utg",
-- "invoiceid": 99748,
-- "item_heading": null,
-- "label": null,
-- "quantity_heading": null,
-- "rate_heading": null,
-- "task_heading": null,
-- "theme_font_name": "modern",
-- "theme_layout": "simple",
-- "theme_primary_color": "#663399",
-- "time_entry_notes_heading": null,
-- "unit_cost_heading": null
-- }
-- }
-- }
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @Date_format int
-- Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.DtObj', @Date_format OUT
EXEC sp_OAMethod @jResp, 'DtOf', @success OUT, 'response.result.presentation.date_format', 0, @Date_format
DECLARE @Description_heading nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Description_heading OUT, 'response.result.presentation.description_heading'
DECLARE @Hours_heading nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Hours_heading OUT, 'response.result.presentation.hours_heading'
DECLARE @Image_banner_position_y int
EXEC sp_OAMethod @jResp, 'IntOf', @Image_banner_position_y OUT, 'response.result.presentation.image_banner_position_y'
DECLARE @Image_banner_src nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Image_banner_src OUT, 'response.result.presentation.image_banner_src'
DECLARE @Image_logo_src nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Image_logo_src OUT, 'response.result.presentation.image_logo_src'
DECLARE @Invoiceid int
EXEC sp_OAMethod @jResp, 'IntOf', @Invoiceid OUT, 'response.result.presentation.invoiceid'
DECLARE @Item_heading nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Item_heading OUT, 'response.result.presentation.item_heading'
DECLARE @Label nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Label OUT, 'response.result.presentation.label'
DECLARE @Quantity_heading nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Quantity_heading OUT, 'response.result.presentation.quantity_heading'
DECLARE @Rate_heading nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Rate_heading OUT, 'response.result.presentation.rate_heading'
DECLARE @Task_heading nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Task_heading OUT, 'response.result.presentation.task_heading'
DECLARE @Theme_font_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Theme_font_name OUT, 'response.result.presentation.theme_font_name'
DECLARE @Theme_layout nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Theme_layout OUT, 'response.result.presentation.theme_layout'
DECLARE @Theme_primary_color nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Theme_primary_color OUT, 'response.result.presentation.theme_primary_color'
DECLARE @Time_entry_notes_heading nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Time_entry_notes_heading OUT, 'response.result.presentation.time_entry_notes_heading'
DECLARE @Unit_cost_heading nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Unit_cost_heading OUT, 'response.result.presentation.unit_cost_heading'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
EXEC @hr = sp_OADestroy @Date_format
END
GO
Curl Command
curl -X GET
-H "Authorization: Bearer <access_token>"
https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/presentations
Postman Collection Item JSON
{
"name": "Get default invoice presentation styles",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/presentations",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"invoices",
"presentations"
]
}
},
"response": [
{
"name": "Get default invoice presentation styles",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/presentations",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"invoices",
"presentations"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gNX0BcCwUGEQoLVhRXUVdXQxdcElQPRwMQX1gPFUEUAxxUT1MHBAVSVAkEAlpVW1EHWgFOFQkYEAIEDFMIAgQAXFcCUlABDQsSSAcDW0JSOw=="
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "0"
},
{
"key": "X-RateLimit-Reset",
"value": "1558636751"
},
{
"key": "Retry-After",
"value": "57"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Wed, 23 May 2018 18:38:13 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Via",
"value": "1.1 varnish"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
},
{
"key": "Date",
"value": "Thu, 23 May 2019 18:38:13 GMT"
},
{
"key": "Age",
"value": "0"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "X-Served-By",
"value": "cache-mdw17381-MDW"
},
{
"key": "X-Cache",
"value": "MISS"
},
{
"key": "X-Cache-Hits",
"value": "0"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Country",
"value": "CA"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains; preload"
}
],
"cookie": [
],
"body": "{\n \"response\": {\n \"result\": {\n \"presentation\": {\n \"date_format\": \"mm/dd/yyyy\",\n \"description_heading\": null,\n \"hours_heading\": null,\n \"image_banner_position_y\": 0,\n \"image_banner_src\": null,\n \"image_logo_src\": \"/uploads/images/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50Ijo0MjM2NDEwLCJvcmlnaW5hbF9maWxlbmFtZSI6InBpenphZG90bmV0LmpwZyIsImxlbmd0aCI6MTA2MDM3LCJmaWxlbmFtZSI6InVwbG9hZC0xM2UwMmRiYzI2ZWEyMmQzYTJmZmY3ZmZmYWUwZjZjMzE5MzUxMWQ4IiwiYnVja2V0IjoidXBsb2FkcyIsImtleSI6Iidkb2NzLSctNDIzNjQxMC91cGxvYWQtMTNlMDJkYmMyNmVhMjJkM2EyZmZmN2ZmZmFlMGY2YzMxOTM1MTFkOCJ9.d7YhBtzuxdiglt5d6eUVZc_dORsnOAJuDx1XvYj2utg\",\n \"invoiceid\": 99748,\n \"item_heading\": null,\n \"label\": null,\n \"quantity_heading\": null,\n \"rate_heading\": null,\n \"task_heading\": null,\n \"theme_font_name\": \"modern\",\n \"theme_layout\": \"simple\",\n \"theme_primary_color\": \"#663399\",\n \"time_entry_notes_heading\": null,\n \"unit_cost_heading\": null\n }\n }\n }\n}"
}
]
}