PowerBuilder / New FreshBooks / Add Payment to Bill
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Amount
string ls_Code
integer li_Billid
integer li_Id
integer li_Matched_with_expense
string ls_Note
string ls_Paid_date
string ls_Payment_type
integer li_Vis_state
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "bill_payment": {
// "billid": "7",
// "amount": {
// "amount": "375",
// "code": "USD"
// },
// "payment_type": "Check",
// "paid_date": "2020-10-09",
// "note": "",
// "bill": null
// }
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("bill_payment.billid","7")
loo_Json.UpdateString("bill_payment.amount.amount","375")
loo_Json.UpdateString("bill_payment.amount.code","USD")
loo_Json.UpdateString("bill_payment.payment_type","Check")
loo_Json.UpdateString("bill_payment.paid_date","2020-10-09")
loo_Json.UpdateString("bill_payment.note","")
loo_Json.UpdateNull("bill_payment.bill")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Resp = loo_Http.PostJson3("https://api.freshbooks.com/accounting/account/{{accountId}}/bill_payments/bill_payments","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "response": {
// "result": {
// "bill_payment": {
// "amount": {
// "amount": "100.00",
// "code": "EUR"
// },
// "billid": 1141,
// "id": 909,
// "matched_with_expense": false,
// "note": "",
// "paid_date": "2021-01-30",
// "payment_type": "Check",
// "vis_state": 0
// }
// }
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
ls_Amount = loo_JResp.StringOf("response.result.bill_payment.amount.amount")
ls_Code = loo_JResp.StringOf("response.result.bill_payment.amount.code")
li_Billid = loo_JResp.IntOf("response.result.bill_payment.billid")
li_Id = loo_JResp.IntOf("response.result.bill_payment.id")
li_Matched_with_expense = loo_JResp.BoolOf("response.result.bill_payment.matched_with_expense")
ls_Note = loo_JResp.StringOf("response.result.bill_payment.note")
ls_Paid_date = loo_JResp.StringOf("response.result.bill_payment.paid_date")
ls_Payment_type = loo_JResp.StringOf("response.result.bill_payment.payment_type")
li_Vis_state = loo_JResp.IntOf("response.result.bill_payment.vis_state")
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"bill_payment": {
"billid": "7",
"amount": {
"amount": "375",
"code": "USD"
},
"payment_type": "Check",
"paid_date": "2020-10-09",
"note": "",
"bill": null
}
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/bill_payments/bill_payments
Postman Collection Item JSON
{
"name": "Add Payment to Bill",
"event": [
{
"listen": "test",
"script": {
"exec": [
"let jsonData = JSON.parse(responseBody);",
"pm.environment.set(\"billPaymentId\", jsonData.response.result.bill_payment.id)"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill_payment\": {\n \"billid\": \"7\",\n \"amount\": {\n \"amount\": \"375\",\n \"code\": \"USD\"\n },\n \"payment_type\": \"Check\",\n \"paid_date\": \"2020-10-09\",\n \"note\": \"\",\n \"bill\": null\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_payments/bill_payments",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bill_payments",
"bill_payments"
]
}
},
"response": [
{
"name": "Add Payment to Bill",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill_payment\": {\n \"billid\": {{billId}},\n \"amount\": {\n \"amount\": \"100\",\n \"code\": \"EUR\"\n },\n \"payment_type\": \"Check\",\n \"paid_date\": \"2021-01-30\",\n \"note\": \"\",\n \"bill\": null\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_payments/bill_payments",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bill_payments",
"bill_payments"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Date",
"value": "Thu, 28 Jan 2021 19:48:34 GMT"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gGWFpfPRYCG10HVhZLAlZbXwlJAEgMVgwQRRVNVk8IHQFTUlcOBAFQUgkOBlFRVlsITgpXCBQWBQBVDwcAAlFXAFIGUwcFDREcAgAORFRq"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self'"
},
{
"key": "X-Content-Security-Policy",
"value": "default-src 'self'"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31556926; includeSubDomains; preload"
},
{
"key": "Referrer-Policy",
"value": "strict-origin-when-cross-origin"
},
{
"key": "X-RateLimit-Limit",
"value": "600"
},
{
"key": "X-RateLimit-Remaining",
"value": "597"
},
{
"key": "X-RateLimit-Reset",
"value": "1611863375"
},
{
"key": "Retry-After",
"value": "60"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Alt-Svc",
"value": "h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "{\n \"response\": {\n \"result\": {\n \"bill_payment\": {\n \"amount\": {\n \"amount\": \"100.00\",\n \"code\": \"EUR\"\n },\n \"billid\": 1141,\n \"id\": 909,\n \"matched_with_expense\": false,\n \"note\": \"\",\n \"paid_date\": \"2021-01-30\",\n \"payment_type\": \"Check\",\n \"vis_state\": 0\n }\n }\n }\n}"
}
]
}