PureBasic / New FreshBooks / Create Recurring Expense
Back to Collection Items
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
; 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
; }
; }
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"expense_profile.frequency","m")
CkJsonObject::ckUpdateNull(json,"expense_profile.profileid")
CkJsonObject::ckUpdateString(json,"expense_profile.start_date","2019-01-13")
CkJsonObject::ckUpdateNull(json,"expense_profile.end_date")
CkJsonObject::ckUpdateString(json,"expense_profile.next_issue_date","2019-01-13")
CkJsonObject::ckUpdateBool(json,"expense_profile.is_cogs",0)
CkJsonObject::ckUpdateString(json,"expense_profile.amount.amount","100")
CkJsonObject::ckUpdateString(json,"expense_profile.amount.code","CAD")
CkJsonObject::ckUpdateNull(json,"expense_profile.notes")
CkJsonObject::ckUpdateString(json,"expense_profile.vendor","Recurring Expenses Inc.")
CkJsonObject::ckUpdateInt(json,"expense_profile.staffid",1)
CkJsonObject::ckUpdateNull(json,"expense_profile.author_name")
CkJsonObject::ckUpdateString(json,"expense_profile.taxName1","HST")
CkJsonObject::ckUpdateNull(json,"expense_profile.taxName2")
CkJsonObject::ckUpdateString(json,"expense_profile.taxAmount1.amount","11.5")
CkJsonObject::ckUpdateString(json,"expense_profile.taxAmount1.code","CAD")
CkJsonObject::ckUpdateInt(json,"expense_profile.taxPercent1",13)
CkJsonObject::ckUpdateNull(json,"expense_profile.taxPercent2")
CkJsonObject::ckUpdateNull(json,"expense_profile.markup_percent")
CkJsonObject::ckUpdateBool(json,"expense_profile.from_bulk_import",0)
CkJsonObject::ckUpdateString(json,"expense_profile.categoryid","4723650")
CkJsonObject::ckUpdateNull(json,"expense_profile.clientid")
; Adds the "Authorization: Bearer <access_token>" header.
CkHttp::setCkAuthToken(http, "<access_token>")
CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
resp.i = CkHttp::ckPostJson3(http,"https://api.freshbooks.com/accounting/account/{{accountid}}/expense_profiles/expense_profiles","application/json",json)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndIf
Debug Str(CkHttpResponse::ckStatusCode(resp))
Debug CkHttpResponse::ckBodyStr(resp)
CkHttpResponse::ckDispose(resp)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure
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": [
]
}