PowerBuilder / New FreshBooks / Delete Credit
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Accounting_systemid
string ls_Amount
string ls_Code
string ls_City
integer li_Clientid
string ls_Credit_noteCode
string ls_Country
string ls_Create_date
string ls_Credit_number
string ls_Credit_type
integer li_Creditid
string ls_Currency_code
string ls_Current_organization
string ls_Description
string ls_Display_status
string ls_Dispute_status
integer li_Ext_archive
string ls_Fname
integer li_Id
string ls_Language
string ls_Last_order_status
string ls_Lname
string ls_Notes
string ls_Organization
string ls_PaidAmount
string ls_PaidCode
string ls_Payment_status
string ls_Province
integer li_Sentid
string ls_Status
string ls_Street
string ls_Street2
string ls_Template
string ls_Terms
string ls_Vat_name
string ls_Vat_number
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.
// {
// "credit_note": {
// "vis_state": 1
// }
// }
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("credit_note.vis_state",1)
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json.EmitSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("PUT","https://api.freshbooks.com/accounting/account/{{accountId}}/credit_notes/credit_notes/{{creditId}}",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
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_SbRequestBody
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": {
// "credit_note": {
// "accounting_systemid": "E86Qp",
// "amount": {
// "amount": "150.00",
// "code": "CAD"
// },
// "city": "",
// "clientid": 599843,
// "code": "",
// "country": "",
// "create_date": "2020-07-31",
// "credit_number": "0000069",
// "credit_type": "goodwill",
// "creditid": 30947,
// "currency_code": "CAD",
// "current_organization": "Squarespace",
// "description": "Goodwill Credit",
// "display_status": "created",
// "dispute_status": null,
// "ext_archive": 0,
// "fname": "",
// "id": 30947,
// "language": "en",
// "last_order_status": null,
// "lname": "",
// "notes": "Free $150 voucher",
// "organization": "Squarespace",
// "paid": {
// "amount": "150.00",
// "code": "CAD"
// },
// "payment_status": "paid",
// "province": "",
// "sentid": 1,
// "status": "created",
// "street": "",
// "street2": "",
// "template": "clean-grouped",
// "terms": "Will be applied to future invoice",
// "vat_name": "",
// "vat_number": "",
// "vis_state": 1
// }
// }
// }
// }
// 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.credit_note.accounting_systemid")
ls_Amount = loo_JResp.StringOf("response.result.credit_note.amount.amount")
ls_Code = loo_JResp.StringOf("response.result.credit_note.amount.code")
ls_City = loo_JResp.StringOf("response.result.credit_note.city")
li_Clientid = loo_JResp.IntOf("response.result.credit_note.clientid")
ls_Credit_noteCode = loo_JResp.StringOf("response.result.credit_note.code")
ls_Country = loo_JResp.StringOf("response.result.credit_note.country")
ls_Create_date = loo_JResp.StringOf("response.result.credit_note.create_date")
ls_Credit_number = loo_JResp.StringOf("response.result.credit_note.credit_number")
ls_Credit_type = loo_JResp.StringOf("response.result.credit_note.credit_type")
li_Creditid = loo_JResp.IntOf("response.result.credit_note.creditid")
ls_Currency_code = loo_JResp.StringOf("response.result.credit_note.currency_code")
ls_Current_organization = loo_JResp.StringOf("response.result.credit_note.current_organization")
ls_Description = loo_JResp.StringOf("response.result.credit_note.description")
ls_Display_status = loo_JResp.StringOf("response.result.credit_note.display_status")
ls_Dispute_status = loo_JResp.StringOf("response.result.credit_note.dispute_status")
li_Ext_archive = loo_JResp.IntOf("response.result.credit_note.ext_archive")
ls_Fname = loo_JResp.StringOf("response.result.credit_note.fname")
li_Id = loo_JResp.IntOf("response.result.credit_note.id")
ls_Language = loo_JResp.StringOf("response.result.credit_note.language")
ls_Last_order_status = loo_JResp.StringOf("response.result.credit_note.last_order_status")
ls_Lname = loo_JResp.StringOf("response.result.credit_note.lname")
ls_Notes = loo_JResp.StringOf("response.result.credit_note.notes")
ls_Organization = loo_JResp.StringOf("response.result.credit_note.organization")
ls_PaidAmount = loo_JResp.StringOf("response.result.credit_note.paid.amount")
ls_PaidCode = loo_JResp.StringOf("response.result.credit_note.paid.code")
ls_Payment_status = loo_JResp.StringOf("response.result.credit_note.payment_status")
ls_Province = loo_JResp.StringOf("response.result.credit_note.province")
li_Sentid = loo_JResp.IntOf("response.result.credit_note.sentid")
ls_Status = loo_JResp.StringOf("response.result.credit_note.status")
ls_Street = loo_JResp.StringOf("response.result.credit_note.street")
ls_Street2 = loo_JResp.StringOf("response.result.credit_note.street2")
ls_Template = loo_JResp.StringOf("response.result.credit_note.template")
ls_Terms = loo_JResp.StringOf("response.result.credit_note.terms")
ls_Vat_name = loo_JResp.StringOf("response.result.credit_note.vat_name")
ls_Vat_number = loo_JResp.StringOf("response.result.credit_note.vat_number")
li_Vis_state = loo_JResp.IntOf("response.result.credit_note.vis_state")
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '{
"credit_note": {
"vis_state": 1
}
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/credit_notes/credit_notes/{{creditId}}
Postman Collection Item JSON
{
"name": "Delete Credit",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"credit_note\": {\n \"vis_state\": 1\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/credit_notes/credit_notes/{{creditId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"credit_notes",
"credit_notes",
"{{creditId}}"
]
}
},
"response": [
{
"name": "Delete Credit",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"credit_note\": {\n \"vis_state\": 1\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/credit_notes/credit_notes/{{creditId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"credit_notes",
"credit_notes",
"{{creditId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Date",
"value": "Fri, 11 Sep 2020 14:41:22 GMT"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gHQ1NXCxI8DF8WXRECW0ZXVwxND14VVkBIBhtRSFALCwZUV1ECBgJRUAUAAVtKV1ccQAAGDlsEBVYECwAGAAsBUwYVTQACVEBVOQ=="
},
{
"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": "595"
},
{
"key": "X-RateLimit-Reset",
"value": "1599835343"
},
{
"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 \"credit_note\": {\n \"accounting_systemid\": \"E86Qp\",\n \"amount\": {\n \"amount\": \"150.00\",\n \"code\": \"CAD\"\n },\n \"city\": \"\",\n \"clientid\": 599843,\n \"code\": \"\",\n \"country\": \"\",\n \"create_date\": \"2020-07-31\",\n \"credit_number\": \"0000069\",\n \"credit_type\": \"goodwill\",\n \"creditid\": 30947,\n \"currency_code\": \"CAD\",\n \"current_organization\": \"Squarespace\",\n \"description\": \"Goodwill Credit\",\n \"display_status\": \"created\",\n \"dispute_status\": null,\n \"ext_archive\": 0,\n \"fname\": \"\",\n \"id\": 30947,\n \"language\": \"en\",\n \"last_order_status\": null,\n \"lname\": \"\",\n \"notes\": \"Free $150 voucher\",\n \"organization\": \"Squarespace\",\n \"paid\": {\n \"amount\": \"150.00\",\n \"code\": \"CAD\"\n },\n \"payment_status\": \"paid\",\n \"province\": \"\",\n \"sentid\": 1,\n \"status\": \"created\",\n \"street\": \"\",\n \"street2\": \"\",\n \"template\": \"clean-grouped\",\n \"terms\": \"Will be applied to future invoice\",\n \"vat_name\": \"\",\n \"vat_number\": \"\",\n \"vis_state\": 1\n }\n }\n }\n}"
}
]
}