PowerBuilder / New FreshBooks / Make Payment
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_Accounting_systemid
string ls_Amount
string ls_Code
integer li_Clientid
string ls_Creditid
string ls_Date
integer li_From_credit
string ls_Gateway
integer li_Id
integer li_Invoiceid
integer li_Logid
string ls_Note
string ls_Orderid
integer li_Overpaymentid
string ls_Transactionid
string ls_V_Type
string ls_Updated
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.
// {
// "payment": {
// "invoiceid": 123,
// "amount": {
// "amount": "3300.00"
// },
// "date": "2019-04-19",
// "type": "Check",
// "note": "Paid in full"
// }
// }
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.UpdateInt("payment.invoiceid",123)
loo_Json.UpdateString("payment.amount.amount","3300.00")
loo_Json.UpdateString("payment.date","2019-04-19")
loo_Json.UpdateString("payment.type","Check")
loo_Json.UpdateString("payment.note","Paid in full")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Resp = loo_Http.PostJson3("https://api.freshbooks.com/accounting/account/{{accountId}}/payments/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": {
// "payment": {
// "accounting_systemid": "wkMd2g",
// "amount": {
// "amount": "180.00",
// "code": "USD"
// },
// "clientid": 31006,
// "creditid": null,
// "date": "2019-04-19",
// "from_credit": false,
// "gateway": null,
// "id": 10318,
// "invoiceid": 34420,
// "logid": 10318,
// "note": "Paid in full",
// "orderid": null,
// "overpaymentid": 10320,
// "transactionid": null,
// "type": "Check",
// "updated": "2019-04-24 14:22:18",
// "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_Accounting_systemid = loo_JResp.StringOf("response.result.payment.accounting_systemid")
ls_Amount = loo_JResp.StringOf("response.result.payment.amount.amount")
ls_Code = loo_JResp.StringOf("response.result.payment.amount.code")
li_Clientid = loo_JResp.IntOf("response.result.payment.clientid")
ls_Creditid = loo_JResp.StringOf("response.result.payment.creditid")
ls_Date = loo_JResp.StringOf("response.result.payment.date")
li_From_credit = loo_JResp.BoolOf("response.result.payment.from_credit")
ls_Gateway = loo_JResp.StringOf("response.result.payment.gateway")
li_Id = loo_JResp.IntOf("response.result.payment.id")
li_Invoiceid = loo_JResp.IntOf("response.result.payment.invoiceid")
li_Logid = loo_JResp.IntOf("response.result.payment.logid")
ls_Note = loo_JResp.StringOf("response.result.payment.note")
ls_Orderid = loo_JResp.StringOf("response.result.payment.orderid")
li_Overpaymentid = loo_JResp.IntOf("response.result.payment.overpaymentid")
ls_Transactionid = loo_JResp.StringOf("response.result.payment.transactionid")
ls_V_Type = loo_JResp.StringOf("response.result.payment.type")
ls_Updated = loo_JResp.StringOf("response.result.payment.updated")
li_Vis_state = loo_JResp.IntOf("response.result.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>"
-H "Content-Type: application/json"
-d '{
"payment":{
"invoiceid": {{invoiceId}},
"amount": {
"amount": "3300.00"
},
"date": "2019-04-19",
"type": "Check",
"note": "Paid in full"
}
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/payments/payments
Postman Collection Item JSON
{
"name": "Make Payment",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"payment\":{\n \"invoiceid\": {{invoiceId}},\n \"amount\": {\n \"amount\": \"3300.00\"\n },\n \"date\": \"2019-04-19\",\n \"type\": \"Check\",\n \"note\": \"Paid in full\"\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/payments/payments",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"payments",
"payments"
]
},
"description": "Add a payment to a specific invoice"
},
"response": [
{
"name": "Make Payment",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"payment\":{\n \"invoiceid\": {{invoiceId}},\n \"amount\": {\n \"amount\": \"3300.00\"\n },\n \"date\": \"2019-04-19\",\n \"type\": \"Check\",\n \"note\": \"Paid in full\"\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/payments/payments",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"payments",
"payments"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gUUE9eBwgXEQoSWRtVXVpGQEcVUR1RHVRRAw5XXloIBwRdVFAECARKVQcOH0AAAVpUAwlTXQlRUFEGClUJQx8EBVpEBDs="
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Tue, 24 Apr 2018 18:22:18 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"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:22:18 GMT"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "X-Served-By",
"value": "cache-mdw17369-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 \"payment\": {\n \"accounting_systemid\": \"wkMd2g\",\n \"amount\": {\n \"amount\": \"180.00\",\n \"code\": \"USD\"\n },\n \"clientid\": 31006,\n \"creditid\": null,\n \"date\": \"2019-04-19\",\n \"from_credit\": false,\n \"gateway\": null,\n \"id\": 10318,\n \"invoiceid\": 34420,\n \"logid\": 10318,\n \"note\": \"Paid in full\",\n \"orderid\": null,\n \"overpaymentid\": 10320,\n \"transactionid\": null,\n \"type\": \"Check\",\n \"updated\": \"2019-04-24 14:22:18\",\n \"vis_state\": 0\n }\n }\n }\n}"
}
]
}