SQL Server / New FreshBooks / Create Recurring Expense
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.
-- {
-- "expense_profile": {
-- "frequency": "m",
-- "profileid": null,
-- "start_date": "2019-01-13",
-- "end_date": null,
-- "next_issue_date": "2019-01-13",
-- "is_cogs": false,
-- "amount": {
-- "amount": "100",
-- "code": "CAD"
-- },
-- "notes": null,
-- "vendor": "Recurring Expenses Inc.",
-- "staffid": 1,
-- "author_name": null,
-- "taxName1": "HST",
-- "taxName2": null,
-- "taxAmount1": {
-- "amount": "11.5",
-- "code": "CAD"
-- },
-- "taxPercent1": 13,
-- "taxPercent2": null,
-- "markup_percent": null,
-- "from_bulk_import": false,
-- "categoryid": "4723650",
-- "clientid": null
-- }
-- }
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, 'UpdateString', @success OUT, 'expense_profile.frequency', 'm'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'expense_profile.profileid'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.start_date', '2019-01-13'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'expense_profile.end_date'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.next_issue_date', '2019-01-13'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'expense_profile.is_cogs', 0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.amount.amount', '100'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.amount.code', 'CAD'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'expense_profile.notes'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.vendor', 'Recurring Expenses Inc.'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'expense_profile.staffid', 1
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'expense_profile.author_name'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.taxName1', 'HST'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'expense_profile.taxName2'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.taxAmount1.amount', '11.5'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.taxAmount1.code', 'CAD'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'expense_profile.taxPercent1', 13
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'expense_profile.taxPercent2'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'expense_profile.markup_percent'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'expense_profile.from_bulk_import', 0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expense_profile.categoryid', '4723650'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'expense_profile.clientid'
-- 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 @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.freshbooks.com/accounting/account/{{accountid}}/expense_profiles/expense_profiles', 'application/json', @json
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
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
END
GO
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '{
"expense_profile": {
"frequency": "m",
"profileid": null,
"start_date": "2019-01-13",
"end_date": null,
"next_issue_date": "2019-01-13",
"is_cogs": false,
"amount": {
"amount": "100",
"code": "CAD"
},
"notes": null,
"vendor": "Recurring Expenses Inc.",
"staffid": 1,
"author_name": null,
"taxName1": "HST",
"taxName2": null,
"taxAmount1": {
"amount": "11.5",
"code": "CAD"
},
"taxPercent1": 13,
"taxPercent2": null,
"markup_percent": null,
"from_bulk_import": false,
"categoryid": "4723650",
"clientid": null
}
}'
https://api.freshbooks.com/accounting/account/{{accountid}}/expense_profiles/expense_profiles
Postman Collection Item JSON
{
"name": "Create Recurring Expense",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"expense_profile\": {\n \"frequency\": \"m\",\n \"profileid\": null,\n \"start_date\": \"2019-01-13\",\n \"end_date\": null,\n \"next_issue_date\": \"2019-01-13\",\n \"is_cogs\": false,\n \"amount\": {\n \"amount\": \"100\",\n \"code\": \"CAD\"\n },\n \"notes\": null,\n \"vendor\": \"Recurring Expenses Inc.\",\n \"staffid\": 1,\n \"author_name\": null,\n \"taxName1\": \"HST\",\n \"taxName2\": null,\n \"taxAmount1\": {\n \"amount\": \"11.5\",\n \"code\": \"CAD\"\n },\n \"taxPercent1\": 13,\n \"taxPercent2\": null,\n \"markup_percent\": null,\n \"from_bulk_import\": false,\n \"categoryid\": \"4723650\",\n \"clientid\": null\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountid}}/expense_profiles/expense_profiles",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountid}}",
"expense_profiles",
"expense_profiles"
]
}
},
"response": [
]
}