Chilkat Online Tools

unicodeC / New FreshBooks / Delete Bill

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *amountAmount;
    const wchar_t *amountCode;
    const wchar_t *Category;
    int Categoryid;
    const wchar_t *categoryCreated_at;
    int categoryId;
    BOOL Is_cogs;
    BOOL Is_editable;
    const wchar_t *Parentid;
    const wchar_t *categoryUpdated_at;
    int categoryVis_state;
    const wchar_t *description;
    int id;
    int list_index;
    const wchar_t *quantity;
    const wchar_t *tax_amount1;
    const wchar_t *tax_amount2;
    const wchar_t *tax_authorityid1;
    const wchar_t *tax_authorityid2;
    const wchar_t *tax_name1;
    const wchar_t *tax_name2;
    const wchar_t *tax_percent1;
    const wchar_t *tax_percent2;
    const wchar_t *total_amountAmount;
    const wchar_t *total_amountCode;
    const wchar_t *unit_costAmount;
    const wchar_t *unit_costCode;
    const wchar_t *Amount;
    const wchar_t *Code;
    const wchar_t *Attachment;
    const wchar_t *Bill_number;
    const wchar_t *Created_at;
    const wchar_t *Currency_code;
    const wchar_t *Due_date;
    int Due_offset_days;
    int Id;
    const wchar_t *Issue_date;
    const wchar_t *Language;
    const wchar_t *OutstandingAmount;
    const wchar_t *OutstandingCode;
    const wchar_t *Overall_category;
    const wchar_t *Overall_description;
    const wchar_t *PaidAmount;
    const wchar_t *PaidCode;
    const wchar_t *Status;
    const wchar_t *Tax_amountAmount;
    const wchar_t *Tax_amountCode;
    const wchar_t *Total_amountAmount;
    const wchar_t *Total_amountCode;
    const wchar_t *Updated_at;
    int Vis_state;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // 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
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateInt(json,L"bill.vis_state",1);

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://api.freshbooks.com/accounting/account/{{accountId}}/bills/bills/{{billId}}",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

    // 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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    Amount = CkJsonObjectW_stringOf(jResp,L"response.result.bill.amount.amount");
    Code = CkJsonObjectW_stringOf(jResp,L"response.result.bill.amount.code");
    Attachment = CkJsonObjectW_stringOf(jResp,L"response.result.bill.attachment");
    Bill_number = CkJsonObjectW_stringOf(jResp,L"response.result.bill.bill_number");
    Created_at = CkJsonObjectW_stringOf(jResp,L"response.result.bill.created_at");
    Currency_code = CkJsonObjectW_stringOf(jResp,L"response.result.bill.currency_code");
    Due_date = CkJsonObjectW_stringOf(jResp,L"response.result.bill.due_date");
    Due_offset_days = CkJsonObjectW_IntOf(jResp,L"response.result.bill.due_offset_days");
    Id = CkJsonObjectW_IntOf(jResp,L"response.result.bill.id");
    Issue_date = CkJsonObjectW_stringOf(jResp,L"response.result.bill.issue_date");
    Language = CkJsonObjectW_stringOf(jResp,L"response.result.bill.language");
    OutstandingAmount = CkJsonObjectW_stringOf(jResp,L"response.result.bill.outstanding.amount");
    OutstandingCode = CkJsonObjectW_stringOf(jResp,L"response.result.bill.outstanding.code");
    Overall_category = CkJsonObjectW_stringOf(jResp,L"response.result.bill.overall_category");
    Overall_description = CkJsonObjectW_stringOf(jResp,L"response.result.bill.overall_description");
    PaidAmount = CkJsonObjectW_stringOf(jResp,L"response.result.bill.paid.amount");
    PaidCode = CkJsonObjectW_stringOf(jResp,L"response.result.bill.paid.code");
    Status = CkJsonObjectW_stringOf(jResp,L"response.result.bill.status");
    Tax_amountAmount = CkJsonObjectW_stringOf(jResp,L"response.result.bill.tax_amount.amount");
    Tax_amountCode = CkJsonObjectW_stringOf(jResp,L"response.result.bill.tax_amount.code");
    Total_amountAmount = CkJsonObjectW_stringOf(jResp,L"response.result.bill.total_amount.amount");
    Total_amountCode = CkJsonObjectW_stringOf(jResp,L"response.result.bill.total_amount.code");
    Updated_at = CkJsonObjectW_stringOf(jResp,L"response.result.bill.updated_at");
    Vis_state = CkJsonObjectW_IntOf(jResp,L"response.result.bill.vis_state");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"response.result.bill.bill_payments");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"response.result.bill.lines");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        amountAmount = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].amount.amount");
        amountCode = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].amount.code");
        Category = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].category.category");
        Categoryid = CkJsonObjectW_IntOf(jResp,L"response.result.bill.lines[i].category.categoryid");
        categoryCreated_at = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].category.created_at");
        categoryId = CkJsonObjectW_IntOf(jResp,L"response.result.bill.lines[i].category.id");
        Is_cogs = CkJsonObjectW_BoolOf(jResp,L"response.result.bill.lines[i].category.is_cogs");
        Is_editable = CkJsonObjectW_BoolOf(jResp,L"response.result.bill.lines[i].category.is_editable");
        Parentid = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].category.parentid");
        categoryUpdated_at = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].category.updated_at");
        categoryVis_state = CkJsonObjectW_IntOf(jResp,L"response.result.bill.lines[i].category.vis_state");
        description = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].description");
        id = CkJsonObjectW_IntOf(jResp,L"response.result.bill.lines[i].id");
        list_index = CkJsonObjectW_IntOf(jResp,L"response.result.bill.lines[i].list_index");
        quantity = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].quantity");
        tax_amount1 = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].tax_amount1");
        tax_amount2 = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].tax_amount2");
        tax_authorityid1 = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].tax_authorityid1");
        tax_authorityid2 = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].tax_authorityid2");
        tax_name1 = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].tax_name1");
        tax_name2 = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].tax_name2");
        tax_percent1 = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].tax_percent1");
        tax_percent2 = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].tax_percent2");
        total_amountAmount = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].total_amount.amount");
        total_amountCode = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].total_amount.code");
        unit_costAmount = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].unit_cost.amount");
        unit_costCode = CkJsonObjectW_stringOf(jResp,L"response.result.bill.lines[i].unit_cost.code");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

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}"
    }
  ]
}