Back to Collection Items
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
Local $bSuccess
; 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": {
; "vis_state": 2
; }
; }
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateInt("bill.vis_state",2)
; Adds the "Authorization: Bearer <access_token>" header.
$oHttp.AuthToken = "<access_token>"
$oSbRequestBody = ObjCreate("Chilkat.StringBuilder")
$oJson.EmitSb($oSbRequestBody)
Local $oResp = $oHttp.PTextSb("PUT","https://api.freshbooks.com/accounting/account/{{accountId}}/bills/bills/{{billId}}",$oSbRequestBody,"utf-8","application/json",False,False)
If ($oHttp.LastMethodSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oResp.Header & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "response": {
; "result": {
; "bill": {
; "amount": {
; "amount": "5.00",
; "code": "CAD"
; },
; "attachment": null,
; "bill_number": null,
; "bill_payments": [
; ],
; "created_at": "2020-10-07 21:33:27",
; "currency_code": "CAD",
; "due_date": "2020-11-06",
; "due_offset_days": 30,
; "id": 3,
; "issue_date": "2020-10-07",
; "language": "en",
; "lines": [
; {
; "amount": {
; "amount": "5.00",
; "code": "CAD"
; },
; "category": {
; "category": "Advertising",
; "categoryid": 65688,
; "created_at": "2016-11-17 14:22:35",
; "id": 65688,
; "is_cogs": true,
; "is_editable": false,
; "parentid": null,
; "updated_at": "2020-08-14 12:52:33",
; "vis_state": 0
; },
; "description": "Food",
; "id": 5,
; "list_index": 1,
; "quantity": "1",
; "tax_amount1": null,
; "tax_amount2": null,
; "tax_authorityid1": null,
; "tax_authorityid2": null,
; "tax_name1": null,
; "tax_name2": null,
; "tax_percent1": null,
; "tax_percent2": null,
; "total_amount": {
; "amount": "5.00",
; "code": "CAD"
; },
; "unit_cost": {
; "amount": "5.00",
; "code": "CAD"
; }
; },
; {
; "amount": {
; "amount": "0.00",
; "code": "CAD"
; },
; "category": {
; "category": "Advertising",
; "categoryid": 65688,
; "created_at": "2016-11-17 14:22:35",
; "id": 65688,
; "is_cogs": true,
; "is_editable": false,
; "parentid": null,
; "updated_at": "2020-08-14 12:52:33",
; "vis_state": 0
; },
; "description": null,
; "id": 7,
; "list_index": 2,
; "quantity": "1",
; "tax_amount1": null,
; "tax_amount2": null,
; "tax_authorityid1": null,
; "tax_authorityid2": null,
; "tax_name1": null,
; "tax_name2": null,
; "tax_percent1": null,
; "tax_percent2": null,
; "total_amount": {
; "amount": "0.00",
; "code": "CAD"
; },
; "unit_cost": {
; "amount": "0.00",
; "code": "CAD"
; }
; }
; ],
; "outstanding": {
; "amount": "5.00",
; "code": "CAD"
; },
; "overall_category": "Advertising",
; "overall_description": "Food",
; "paid": {
; "amount": "0.00",
; "code": "CAD"
; },
; "status": "unpaid",
; "tax_amount": {
; "amount": "0.00",
; "code": "CAD"
; },
; "total_amount": {
; "amount": "5.00",
; "code": "CAD"
; },
; "updated_at": "2020-10-09 15:41:35",
; "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
Local $sAmountAmount
Local $sAmountCode
Local $sCategory
Local $iCategoryid
Local $sCategoryCreated_at
Local $iCategoryId
Local $bIs_cogs
Local $bIs_editable
Local $sParentid
Local $sCategoryUpdated_at
Local $iCategoryVis_state
Local $sDescription
Local $id
Local $iList_index
Local $sQuantity
Local $sTax_amount1
Local $sTax_amount2
Local $sTax_authorityid1
Local $sTax_authorityid2
Local $sTax_name1
Local $sTax_name2
Local $sTax_percent1
Local $sTax_percent2
Local $sTotal_amountAmount
Local $sTotal_amountCode
Local $sUnit_costAmount
Local $sUnit_costCode
Local $sAmount = $oJResp.StringOf("response.result.bill.amount.amount")
Local $sCode = $oJResp.StringOf("response.result.bill.amount.code")
Local $sAttachment = $oJResp.StringOf("response.result.bill.attachment")
Local $sBill_number = $oJResp.StringOf("response.result.bill.bill_number")
Local $sCreated_at = $oJResp.StringOf("response.result.bill.created_at")
Local $sCurrency_code = $oJResp.StringOf("response.result.bill.currency_code")
Local $sDue_date = $oJResp.StringOf("response.result.bill.due_date")
Local $iDue_offset_days = $oJResp.IntOf("response.result.bill.due_offset_days")
Local $iId = $oJResp.IntOf("response.result.bill.id")
Local $sIssue_date = $oJResp.StringOf("response.result.bill.issue_date")
Local $sLanguage = $oJResp.StringOf("response.result.bill.language")
Local $sOutstandingAmount = $oJResp.StringOf("response.result.bill.outstanding.amount")
Local $sOutstandingCode = $oJResp.StringOf("response.result.bill.outstanding.code")
Local $sOverall_category = $oJResp.StringOf("response.result.bill.overall_category")
Local $sOverall_description = $oJResp.StringOf("response.result.bill.overall_description")
Local $sPaidAmount = $oJResp.StringOf("response.result.bill.paid.amount")
Local $sPaidCode = $oJResp.StringOf("response.result.bill.paid.code")
Local $sStatus = $oJResp.StringOf("response.result.bill.status")
Local $sTax_amountAmount = $oJResp.StringOf("response.result.bill.tax_amount.amount")
Local $sTax_amountCode = $oJResp.StringOf("response.result.bill.tax_amount.code")
Local $sTotal_amountAmount = $oJResp.StringOf("response.result.bill.total_amount.amount")
Local $sTotal_amountCode = $oJResp.StringOf("response.result.bill.total_amount.code")
Local $sUpdated_at = $oJResp.StringOf("response.result.bill.updated_at")
Local $iVis_state = $oJResp.IntOf("response.result.bill.vis_state")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("response.result.bill.bill_payments")
While $i < $iCount_i
$oJResp.I = $i
$i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("response.result.bill.lines")
While $i < $iCount_i
$oJResp.I = $i
$sAmountAmount = $oJResp.StringOf("response.result.bill.lines[i].amount.amount")
$sAmountCode = $oJResp.StringOf("response.result.bill.lines[i].amount.code")
$sCategory = $oJResp.StringOf("response.result.bill.lines[i].category.category")
$iCategoryid = $oJResp.IntOf("response.result.bill.lines[i].category.categoryid")
$sCategoryCreated_at = $oJResp.StringOf("response.result.bill.lines[i].category.created_at")
$iCategoryId = $oJResp.IntOf("response.result.bill.lines[i].category.id")
$bIs_cogs = $oJResp.BoolOf("response.result.bill.lines[i].category.is_cogs")
$bIs_editable = $oJResp.BoolOf("response.result.bill.lines[i].category.is_editable")
$sParentid = $oJResp.StringOf("response.result.bill.lines[i].category.parentid")
$sCategoryUpdated_at = $oJResp.StringOf("response.result.bill.lines[i].category.updated_at")
$iCategoryVis_state = $oJResp.IntOf("response.result.bill.lines[i].category.vis_state")
$sDescription = $oJResp.StringOf("response.result.bill.lines[i].description")
$id = $oJResp.IntOf("response.result.bill.lines[i].id")
$iList_index = $oJResp.IntOf("response.result.bill.lines[i].list_index")
$sQuantity = $oJResp.StringOf("response.result.bill.lines[i].quantity")
$sTax_amount1 = $oJResp.StringOf("response.result.bill.lines[i].tax_amount1")
$sTax_amount2 = $oJResp.StringOf("response.result.bill.lines[i].tax_amount2")
$sTax_authorityid1 = $oJResp.StringOf("response.result.bill.lines[i].tax_authorityid1")
$sTax_authorityid2 = $oJResp.StringOf("response.result.bill.lines[i].tax_authorityid2")
$sTax_name1 = $oJResp.StringOf("response.result.bill.lines[i].tax_name1")
$sTax_name2 = $oJResp.StringOf("response.result.bill.lines[i].tax_name2")
$sTax_percent1 = $oJResp.StringOf("response.result.bill.lines[i].tax_percent1")
$sTax_percent2 = $oJResp.StringOf("response.result.bill.lines[i].tax_percent2")
$sTotal_amountAmount = $oJResp.StringOf("response.result.bill.lines[i].total_amount.amount")
$sTotal_amountCode = $oJResp.StringOf("response.result.bill.lines[i].total_amount.code")
$sUnit_costAmount = $oJResp.StringOf("response.result.bill.lines[i].unit_cost.amount")
$sUnit_costCode = $oJResp.StringOf("response.result.bill.lines[i].unit_cost.code")
$i = $i + 1
Wend
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '{
"bill": {
"vis_state": 2
}
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/bills/bills/{{billId}}
Postman Collection Item JSON
{
"name": "Archive Bill",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill\": {\n \"vis_state\": 2\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bills/bills/{{billId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bills",
"bills",
"{{billId}}"
]
}
},
"response": [
{
"name": "Delete Bill",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill\": {\n \"vis_state\": 1\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bills/bills/{{billId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bills",
"bills",
"{{billId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Date",
"value": "Fri, 09 Oct 2020 15:41:35 GMT"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gGWFpfEVwBC1wOGk4IFAQcAFEJUQRSA1pVAwZTUlYJAgdIVVQbEwRfUAMGBgRUWlAIUwBQXAAWHlUEVRJUPA=="
},
{
"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": "599"
},
{
"key": "X-RateLimit-Reset",
"value": "1602258156"
},
{
"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\": {\n \"amount\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"attachment\": null,\n \"bill_number\": null,\n \"bill_payments\": [],\n \"created_at\": \"2020-10-07 21:33:27\",\n \"currency_code\": \"CAD\",\n \"due_date\": \"2020-11-06\",\n \"due_offset_days\": 30,\n \"id\": 3,\n \"issue_date\": \"2020-10-07\",\n \"language\": \"en\",\n \"lines\": [\n {\n \"amount\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"category\": {\n \"category\": \"Advertising\",\n \"categoryid\": 65688,\n \"created_at\": \"2016-11-17 14:22:35\",\n \"id\": 65688,\n \"is_cogs\": true,\n \"is_editable\": false,\n \"parentid\": null,\n \"updated_at\": \"2020-08-14 12:52:33\",\n \"vis_state\": 0\n },\n \"description\": \"Food\",\n \"id\": 5,\n \"list_index\": 1,\n \"quantity\": \"1\",\n \"tax_amount1\": null,\n \"tax_amount2\": null,\n \"tax_authorityid1\": null,\n \"tax_authorityid2\": null,\n \"tax_name1\": null,\n \"tax_name2\": null,\n \"tax_percent1\": null,\n \"tax_percent2\": null,\n \"total_amount\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"unit_cost\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n }\n },\n {\n \"amount\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n },\n \"category\": {\n \"category\": \"Advertising\",\n \"categoryid\": 65688,\n \"created_at\": \"2016-11-17 14:22:35\",\n \"id\": 65688,\n \"is_cogs\": true,\n \"is_editable\": false,\n \"parentid\": null,\n \"updated_at\": \"2020-08-14 12:52:33\",\n \"vis_state\": 0\n },\n \"description\": null,\n \"id\": 7,\n \"list_index\": 2,\n \"quantity\": \"1\",\n \"tax_amount1\": null,\n \"tax_amount2\": null,\n \"tax_authorityid1\": null,\n \"tax_authorityid2\": null,\n \"tax_name1\": null,\n \"tax_name2\": null,\n \"tax_percent1\": null,\n \"tax_percent2\": null,\n \"total_amount\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n },\n \"unit_cost\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n }\n }\n ],\n \"outstanding\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"overall_category\": \"Advertising\",\n \"overall_description\": \"Food\",\n \"paid\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n },\n \"status\": \"unpaid\",\n \"tax_amount\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n },\n \"total_amount\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"updated_at\": \"2020-10-09 15:41:35\",\n \"vis_state\": 1\n }\n }\n }\n}"
},
{
"name": "Archive Bill",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill\": {\n \"vis_state\": 2\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bills/bills/{{billId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bills",
"bills",
"{{billId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Date",
"value": "Fri, 09 Oct 2020 15:42:25 GMT"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gGWFpfEVwBC1wOGk4IFAQcB1cNVwhXAVJTBgNXU1MACxxQV04VVAQHAQFUBAFRAFVVAFlUDxoYVFIJSgRs"
},
{
"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": "598"
},
{
"key": "X-RateLimit-Reset",
"value": "1602258206"
},
{
"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\": {\n \"amount\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"attachment\": null,\n \"bill_number\": null,\n \"bill_payments\": [],\n \"created_at\": \"2020-10-07 21:33:27\",\n \"currency_code\": \"CAD\",\n \"due_date\": \"2020-11-06\",\n \"due_offset_days\": 30,\n \"id\": 3,\n \"issue_date\": \"2020-10-07\",\n \"language\": \"en\",\n \"lines\": [\n {\n \"amount\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"category\": {\n \"category\": \"Advertising\",\n \"categoryid\": 65688,\n \"created_at\": \"2016-11-17 14:22:35\",\n \"id\": 65688,\n \"is_cogs\": true,\n \"is_editable\": false,\n \"parentid\": null,\n \"updated_at\": \"2020-08-14 12:52:33\",\n \"vis_state\": 0\n },\n \"description\": \"Food\",\n \"id\": 5,\n \"list_index\": 1,\n \"quantity\": \"1\",\n \"tax_amount1\": null,\n \"tax_amount2\": null,\n \"tax_authorityid1\": null,\n \"tax_authorityid2\": null,\n \"tax_name1\": null,\n \"tax_name2\": null,\n \"tax_percent1\": null,\n \"tax_percent2\": null,\n \"total_amount\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"unit_cost\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n }\n },\n {\n \"amount\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n },\n \"category\": {\n \"category\": \"Advertising\",\n \"categoryid\": 65688,\n \"created_at\": \"2016-11-17 14:22:35\",\n \"id\": 65688,\n \"is_cogs\": true,\n \"is_editable\": false,\n \"parentid\": null,\n \"updated_at\": \"2020-08-14 12:52:33\",\n \"vis_state\": 0\n },\n \"description\": null,\n \"id\": 7,\n \"list_index\": 2,\n \"quantity\": \"1\",\n \"tax_amount1\": null,\n \"tax_amount2\": null,\n \"tax_authorityid1\": null,\n \"tax_authorityid2\": null,\n \"tax_name1\": null,\n \"tax_name2\": null,\n \"tax_percent1\": null,\n \"tax_percent2\": null,\n \"total_amount\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n },\n \"unit_cost\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n }\n }\n ],\n \"outstanding\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"overall_category\": \"Advertising\",\n \"overall_description\": \"Food\",\n \"paid\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n },\n \"status\": \"unpaid\",\n \"tax_amount\": {\n \"amount\": \"0.00\",\n \"code\": \"CAD\"\n },\n \"total_amount\": {\n \"amount\": \"5.00\",\n \"code\": \"CAD\"\n },\n \"updated_at\": \"2020-10-09 15:42:26\",\n \"vis_state\": 2\n }\n }\n }\n}"
}
]
}