Chilkat Online Tools

DataFlex / New FreshBooks / Create Recurring Expense

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "expense_profile.frequency" "m" To iSuccess
    Get ComUpdateNull Of hoJson "expense_profile.profileid" To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.start_date" "2019-01-13" To iSuccess
    Get ComUpdateNull Of hoJson "expense_profile.end_date" To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.next_issue_date" "2019-01-13" To iSuccess
    Get ComUpdateBool Of hoJson "expense_profile.is_cogs" False To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.amount.amount" "100" To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.amount.code" "CAD" To iSuccess
    Get ComUpdateNull Of hoJson "expense_profile.notes" To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.vendor" "Recurring Expenses Inc." To iSuccess
    Get ComUpdateInt Of hoJson "expense_profile.staffid" 1 To iSuccess
    Get ComUpdateNull Of hoJson "expense_profile.author_name" To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.taxName1" "HST" To iSuccess
    Get ComUpdateNull Of hoJson "expense_profile.taxName2" To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.taxAmount1.amount" "11.5" To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.taxAmount1.code" "CAD" To iSuccess
    Get ComUpdateInt Of hoJson "expense_profile.taxPercent1" 13 To iSuccess
    Get ComUpdateNull Of hoJson "expense_profile.taxPercent2" To iSuccess
    Get ComUpdateNull Of hoJson "expense_profile.markup_percent" To iSuccess
    Get ComUpdateBool Of hoJson "expense_profile.from_bulk_import" False To iSuccess
    Get ComUpdateString Of hoJson "expense_profile.categoryid" "4723650" To iSuccess
    Get ComUpdateNull Of hoJson "expense_profile.clientid" To iSuccess

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.freshbooks.com/accounting/account/{{accountid}}/expense_profiles/expense_profiles" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

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": [
  ]
}