Chilkat Online Tools

DataFlex / New FreshBooks / Delete Bill

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sAmountAmount
    String sAmountCode
    String sCategory
    Integer iCategoryid
    String sCategoryCreated_at
    Integer iCategoryId
    Boolean iIs_cogs
    Boolean iIs_editable
    String sParentid
    String sCategoryUpdated_at
    Integer iCategoryVis_state
    String sDescription
    Integer iId
    Integer iList_index
    String sQuantity
    String sTax_amount1
    String sTax_amount2
    String sTax_authorityid1
    String sTax_authorityid2
    String sTax_name1
    String sTax_name2
    String sTax_percent1
    String sTax_percent2
    String sTotal_amountAmount
    String sTotal_amountCode
    String sUnit_costAmount
    String sUnit_costCode
    String sAmount
    String sCode
    String sAttachment
    String sBill_number
    String sCreated_at
    String sCurrency_code
    String sDue_date
    Integer iDue_offset_days
    Integer iId
    String sIssue_date
    String sLanguage
    String sOutstandingAmount
    String sOutstandingCode
    String sOverall_category
    String sOverall_description
    String sPaidAmount
    String sPaidCode
    String sStatus
    String sTax_amountAmount
    String sTax_amountCode
    String sTotal_amountAmount
    String sTotal_amountCode
    String sUpdated_at
    Integer iVis_state
    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.

    // {
    //   "bill": {
    //     "vis_state": 1
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateInt Of hoJson "bill.vis_state" 1 To iSuccess

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess

    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComPTextSb Of hoHttp "PUT" "https://api.freshbooks.com/accounting/account/{{accountId}}/bills/bills/{{billId}}" vSbRequestBody "utf-8" "application/json" False False 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": {
    //       "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

    Get ComStringOf Of hoJResp "response.result.bill.amount.amount" To sAmount
    Get ComStringOf Of hoJResp "response.result.bill.amount.code" To sCode
    Get ComStringOf Of hoJResp "response.result.bill.attachment" To sAttachment
    Get ComStringOf Of hoJResp "response.result.bill.bill_number" To sBill_number
    Get ComStringOf Of hoJResp "response.result.bill.created_at" To sCreated_at
    Get ComStringOf Of hoJResp "response.result.bill.currency_code" To sCurrency_code
    Get ComStringOf Of hoJResp "response.result.bill.due_date" To sDue_date
    Get ComIntOf Of hoJResp "response.result.bill.due_offset_days" To iDue_offset_days
    Get ComIntOf Of hoJResp "response.result.bill.id" To iId
    Get ComStringOf Of hoJResp "response.result.bill.issue_date" To sIssue_date
    Get ComStringOf Of hoJResp "response.result.bill.language" To sLanguage
    Get ComStringOf Of hoJResp "response.result.bill.outstanding.amount" To sOutstandingAmount
    Get ComStringOf Of hoJResp "response.result.bill.outstanding.code" To sOutstandingCode
    Get ComStringOf Of hoJResp "response.result.bill.overall_category" To sOverall_category
    Get ComStringOf Of hoJResp "response.result.bill.overall_description" To sOverall_description
    Get ComStringOf Of hoJResp "response.result.bill.paid.amount" To sPaidAmount
    Get ComStringOf Of hoJResp "response.result.bill.paid.code" To sPaidCode
    Get ComStringOf Of hoJResp "response.result.bill.status" To sStatus
    Get ComStringOf Of hoJResp "response.result.bill.tax_amount.amount" To sTax_amountAmount
    Get ComStringOf Of hoJResp "response.result.bill.tax_amount.code" To sTax_amountCode
    Get ComStringOf Of hoJResp "response.result.bill.total_amount.amount" To sTotal_amountAmount
    Get ComStringOf Of hoJResp "response.result.bill.total_amount.code" To sTotal_amountCode
    Get ComStringOf Of hoJResp "response.result.bill.updated_at" To sUpdated_at
    Get ComIntOf Of hoJResp "response.result.bill.vis_state" To iVis_state
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "response.result.bill.bill_payments" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "response.result.bill.lines" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].amount.amount" To sAmountAmount
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].amount.code" To sAmountCode
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].category.category" To sCategory
        Get ComIntOf Of hoJResp "response.result.bill.lines[i].category.categoryid" To iCategoryid
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].category.created_at" To sCategoryCreated_at
        Get ComIntOf Of hoJResp "response.result.bill.lines[i].category.id" To iCategoryId
        Get ComBoolOf Of hoJResp "response.result.bill.lines[i].category.is_cogs" To iIs_cogs
        Get ComBoolOf Of hoJResp "response.result.bill.lines[i].category.is_editable" To iIs_editable
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].category.parentid" To sParentid
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].category.updated_at" To sCategoryUpdated_at
        Get ComIntOf Of hoJResp "response.result.bill.lines[i].category.vis_state" To iCategoryVis_state
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].description" To sDescription
        Get ComIntOf Of hoJResp "response.result.bill.lines[i].id" To iId
        Get ComIntOf Of hoJResp "response.result.bill.lines[i].list_index" To iList_index
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].quantity" To sQuantity
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].tax_amount1" To sTax_amount1
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].tax_amount2" To sTax_amount2
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].tax_authorityid1" To sTax_authorityid1
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].tax_authorityid2" To sTax_authorityid2
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].tax_name1" To sTax_name1
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].tax_name2" To sTax_name2
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].tax_percent1" To sTax_percent1
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].tax_percent2" To sTax_percent2
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].total_amount.amount" To sTotal_amountAmount
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].total_amount.code" To sTotal_amountCode
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].unit_cost.amount" To sUnit_costAmount
        Get ComStringOf Of hoJResp "response.result.bill.lines[i].unit_cost.code" To sUnit_costCode
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '{
    "bill": {
        "vis_state": 1
    }
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/bills/bills/{{billId}}

Postman Collection Item JSON

{
  "name": "Delete Bill",
  "request": {
    "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}}"
      ]
    }
  },
  "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}"
    }
  ]
}