Chilkat Online Tools

C / New FreshBooks / Delete Credit

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkHttpResponse resp;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *Accounting_systemid;
    const char *Amount;
    const char *Code;
    const char *City;
    int Clientid;
    const char *Credit_noteCode;
    const char *Country;
    const char *Create_date;
    const char *Credit_number;
    const char *Credit_type;
    int Creditid;
    const char *Currency_code;
    const char *Current_organization;
    const char *Description;
    const char *Display_status;
    const char *Dispute_status;
    int Ext_archive;
    const char *Fname;
    int Id;
    const char *Language;
    const char *Last_order_status;
    const char *Lname;
    const char *Notes;
    const char *Organization;
    const char *PaidAmount;
    const char *PaidCode;
    const char *Payment_status;
    const char *Province;
    int Sentid;
    const char *Status;
    const char *Street;
    const char *Street2;
    const char *Template;
    const char *Terms;
    const char *Vat_name;
    const char *Vat_number;
    int Vis_state;

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

    http = CkHttp_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.

    // {
    //   "credit_note": {
    //     "vis_state": 1
    //   }
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateInt(json,"credit_note.vis_state",1);

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

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);

    resp = CkHttp_PTextSb(http,"PUT","https://api.freshbooks.com/accounting/account/{{accountId}}/credit_notes/credit_notes/{{creditId}}",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        return;
    }

    sbResponseBody = CkStringBuilder_Create();
    CkHttpResponse_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Failed.\n");
        CkHttpResponse_Dispose(resp);
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

    CkHttpResponse_Dispose(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

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

    Accounting_systemid = CkJsonObject_stringOf(jResp,"response.result.credit_note.accounting_systemid");
    Amount = CkJsonObject_stringOf(jResp,"response.result.credit_note.amount.amount");
    Code = CkJsonObject_stringOf(jResp,"response.result.credit_note.amount.code");
    City = CkJsonObject_stringOf(jResp,"response.result.credit_note.city");
    Clientid = CkJsonObject_IntOf(jResp,"response.result.credit_note.clientid");
    Credit_noteCode = CkJsonObject_stringOf(jResp,"response.result.credit_note.code");
    Country = CkJsonObject_stringOf(jResp,"response.result.credit_note.country");
    Create_date = CkJsonObject_stringOf(jResp,"response.result.credit_note.create_date");
    Credit_number = CkJsonObject_stringOf(jResp,"response.result.credit_note.credit_number");
    Credit_type = CkJsonObject_stringOf(jResp,"response.result.credit_note.credit_type");
    Creditid = CkJsonObject_IntOf(jResp,"response.result.credit_note.creditid");
    Currency_code = CkJsonObject_stringOf(jResp,"response.result.credit_note.currency_code");
    Current_organization = CkJsonObject_stringOf(jResp,"response.result.credit_note.current_organization");
    Description = CkJsonObject_stringOf(jResp,"response.result.credit_note.description");
    Display_status = CkJsonObject_stringOf(jResp,"response.result.credit_note.display_status");
    Dispute_status = CkJsonObject_stringOf(jResp,"response.result.credit_note.dispute_status");
    Ext_archive = CkJsonObject_IntOf(jResp,"response.result.credit_note.ext_archive");
    Fname = CkJsonObject_stringOf(jResp,"response.result.credit_note.fname");
    Id = CkJsonObject_IntOf(jResp,"response.result.credit_note.id");
    Language = CkJsonObject_stringOf(jResp,"response.result.credit_note.language");
    Last_order_status = CkJsonObject_stringOf(jResp,"response.result.credit_note.last_order_status");
    Lname = CkJsonObject_stringOf(jResp,"response.result.credit_note.lname");
    Notes = CkJsonObject_stringOf(jResp,"response.result.credit_note.notes");
    Organization = CkJsonObject_stringOf(jResp,"response.result.credit_note.organization");
    PaidAmount = CkJsonObject_stringOf(jResp,"response.result.credit_note.paid.amount");
    PaidCode = CkJsonObject_stringOf(jResp,"response.result.credit_note.paid.code");
    Payment_status = CkJsonObject_stringOf(jResp,"response.result.credit_note.payment_status");
    Province = CkJsonObject_stringOf(jResp,"response.result.credit_note.province");
    Sentid = CkJsonObject_IntOf(jResp,"response.result.credit_note.sentid");
    Status = CkJsonObject_stringOf(jResp,"response.result.credit_note.status");
    Street = CkJsonObject_stringOf(jResp,"response.result.credit_note.street");
    Street2 = CkJsonObject_stringOf(jResp,"response.result.credit_note.street2");
    Template = CkJsonObject_stringOf(jResp,"response.result.credit_note.template");
    Terms = CkJsonObject_stringOf(jResp,"response.result.credit_note.terms");
    Vat_name = CkJsonObject_stringOf(jResp,"response.result.credit_note.vat_name");
    Vat_number = CkJsonObject_stringOf(jResp,"response.result.credit_note.vat_number");
    Vis_state = CkJsonObject_IntOf(jResp,"response.result.credit_note.vis_state");


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(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}"
    }
  ]
}