Chilkat Online Tools

DataFlex / New FreshBooks / Add Journal Entry

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sCredit
    String sCurrency_code
    String sDebit
    String sDescription
    Integer iDetailid
    Integer iId
    String sName
    Integer iSub_accountid
    String sUser_entered_date
    String sCurrency_code
    String sDescription
    Integer iEntryid
    Integer iId
    String sName
    String sUser_entered_date
    Integer i
    Integer iCount_i
    String sTemp1
    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.

    // {
    //   "journal_entry": {
    //     "details": [
    //       {
    //         "sub_accountid": "635974",
    //         "debit": "200"
    //       },
    //       {
    //         "sub_accountid": "635976",
    //         "credit": "200"
    //       }
    //     ],
    //     "currency_code": "USD",
    //     "description": "Here is a basic description of the journal entry made.",
    //     "name": "JournalEntry",
    //     "user_entered_date": "2019-04-20"
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "journal_entry.details[0].sub_accountid" "635974" To iSuccess
    Get ComUpdateString Of hoJson "journal_entry.details[0].debit" "200" To iSuccess
    Get ComUpdateString Of hoJson "journal_entry.details[1].sub_accountid" "635976" To iSuccess
    Get ComUpdateString Of hoJson "journal_entry.details[1].credit" "200" To iSuccess
    Get ComUpdateString Of hoJson "journal_entry.currency_code" "USD" To iSuccess
    Get ComUpdateString Of hoJson "journal_entry.description" "Here is a basic description of the journal entry made." To iSuccess
    Get ComUpdateString Of hoJson "journal_entry.name" "JournalEntry" To iSuccess
    Get ComUpdateString Of hoJson "journal_entry.user_entered_date" "2019-04-20" 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://my.freshbooks.com/service/api/accounting/account/{{accountId}}/journal_entries/journal_entries" "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 Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "response": {
    //     "result": {
    //       "journal_entry": {
    //         "currency_code": "USD",
    //         "description": "Here is a basic description of the journal entry made.",
    //         "details": [
    //           {
    //             "credit": null,
    //             "currency_code": "USD",
    //             "debit": "200",
    //             "description": "Here is a basic description of the journal entry made.",
    //             "detailid": 1313598,
    //             "id": 1313598,
    //             "name": "JournalEntry",
    //             "sub_accountid": 635974,
    //             "user_entered_date": "2019-04-20"
    //           },
    //           {
    //             "credit": "200",
    //             "currency_code": "USD",
    //             "debit": null,
    //             "description": "Here is a basic description of the journal entry made.",
    //             "detailid": 1313600,
    //             "id": 1313600,
    //             "name": "JournalEntry",
    //             "sub_accountid": 635976,
    //             "user_entered_date": "2019-04-20"
    //           }
    //         ],
    //         "entryid": 629310,
    //         "id": 629310,
    //         "name": "JournalEntry",
    //         "user_entered_date": "2019-04-20"
    //       }
    //     }
    //   }
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    Get ComStringOf Of hoJResp "response.result.journal_entry.currency_code" To sCurrency_code
    Get ComStringOf Of hoJResp "response.result.journal_entry.description" To sDescription
    Get ComIntOf Of hoJResp "response.result.journal_entry.entryid" To iEntryid
    Get ComIntOf Of hoJResp "response.result.journal_entry.id" To iId
    Get ComStringOf Of hoJResp "response.result.journal_entry.name" To sName
    Get ComStringOf Of hoJResp "response.result.journal_entry.user_entered_date" To sUser_entered_date
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "response.result.journal_entry.details" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "response.result.journal_entry.details[i].credit" To sCredit
        Get ComStringOf Of hoJResp "response.result.journal_entry.details[i].currency_code" To sCurrency_code
        Get ComStringOf Of hoJResp "response.result.journal_entry.details[i].debit" To sDebit
        Get ComStringOf Of hoJResp "response.result.journal_entry.details[i].description" To sDescription
        Get ComIntOf Of hoJResp "response.result.journal_entry.details[i].detailid" To iDetailid
        Get ComIntOf Of hoJResp "response.result.journal_entry.details[i].id" To iId
        Get ComStringOf Of hoJResp "response.result.journal_entry.details[i].name" To sName
        Get ComIntOf Of hoJResp "response.result.journal_entry.details[i].sub_accountid" To iSub_accountid
        Get ComStringOf Of hoJResp "response.result.journal_entry.details[i].user_entered_date" To sUser_entered_date
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
  "journal_entry": {
    "details": [
      {
        "sub_accountid": "635974",
        "debit": "200"
      },
      {
        "sub_accountid": "635976",
        "credit": "200"
      }
    ],
    "currency_code": "USD",
    "description": "Here is a basic description of the journal entry made.",
    "name": "JournalEntry",
    "user_entered_date": "2019-04-20"
  }
}'
https://my.freshbooks.com/service/api/accounting/account/{{accountId}}/journal_entries/journal_entries

Postman Collection Item JSON

{
  "name": "Add Journal Entry",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"journal_entry\": {\n    \"details\": [\n      {\n        \"sub_accountid\": \"635974\",\n        \"debit\": \"200\"\n      },\n      {\n        \"sub_accountid\": \"635976\",\n        \"credit\": \"200\"\n      }\n    ],\n    \"currency_code\": \"USD\",\n    \"description\": \"Here is a basic description of the journal entry made.\",\n    \"name\": \"JournalEntry\",\n    \"user_entered_date\": \"2019-04-20\"\n  }\n}"
    },
    "url": {
      "raw": "https://my.freshbooks.com/service/api/accounting/account/{{accountId}}/journal_entries/journal_entries",
      "protocol": "https",
      "host": [
        "my",
        "freshbooks",
        "com"
      ],
      "path": [
        "service",
        "api",
        "accounting",
        "account",
        "{{accountId}}",
        "journal_entries",
        "journal_entries"
      ]
    }
  },
  "response": [
    {
      "name": "Add Journal Entry",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"journal_entry\": {\n    \"details\": [\n      {\n        \"sub_accountid\": \"635974\",\n        \"debit\": \"200\"\n      },\n      {\n        \"sub_accountid\": \"635976\",\n        \"credit\": \"200\"\n      }\n    ],\n    \"currency_code\": \"USD\",\n    \"description\": \"Here is a basic description of the journal entry made.\",\n    \"name\": \"JournalEntry\",\n    \"user_entered_date\": \"2019-04-20\"\n  }\n}"
        },
        "url": {
          "raw": "https://my.freshbooks.com/service/api/accounting/account/{{accountId}}/journal_entries/journal_entries",
          "protocol": "https",
          "host": [
            "my",
            "freshbooks",
            "com"
          ],
          "path": [
            "service",
            "api",
            "accounting",
            "account",
            "{{accountId}}",
            "journal_entries",
            "journal_entries"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gOXkNBDAcPPVUMTBBRXUcIWQpME18AXwcKQkUYFAZLXEUWAgcVHQdKVB8HAlFWUFEFUQtSAQ4HAwBRAU0CVgBORlRVBFEAWVFRXFQDBFdWB10TGlUDChAHbQ=="
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Tue, 24 Apr 2018 18:46:24 GMT"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Via",
          "value": "1.1 google"
        },
        {
          "key": "Via",
          "value": "1.1 varnish"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Date",
          "value": "Wed, 24 Apr 2019 18:46:24 GMT"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Served-By",
          "value": "cache-mdw17363-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            \"journal_entry\": {\n                \"currency_code\": \"USD\",\n                \"description\": \"Here is a basic description of the journal entry made.\",\n                \"details\": [\n                    {\n                        \"credit\": null,\n                        \"currency_code\": \"USD\",\n                        \"debit\": \"200\",\n                        \"description\": \"Here is a basic description of the journal entry made.\",\n                        \"detailid\": 1313598,\n                        \"id\": 1313598,\n                        \"name\": \"JournalEntry\",\n                        \"sub_accountid\": 635974,\n                        \"user_entered_date\": \"2019-04-20\"\n                    },\n                    {\n                        \"credit\": \"200\",\n                        \"currency_code\": \"USD\",\n                        \"debit\": null,\n                        \"description\": \"Here is a basic description of the journal entry made.\",\n                        \"detailid\": 1313600,\n                        \"id\": 1313600,\n                        \"name\": \"JournalEntry\",\n                        \"sub_accountid\": 635976,\n                        \"user_entered_date\": \"2019-04-20\"\n                    }\n                ],\n                \"entryid\": 629310,\n                \"id\": 629310,\n                \"name\": \"JournalEntry\",\n                \"user_entered_date\": \"2019-04-20\"\n            }\n        }\n    }\n}"
    }
  ]
}