Chilkat Online Tools

Foxpro / New FreshBooks / Delete Credit

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcAccounting_systemid
LOCAL lcAmount
LOCAL lcCode
LOCAL lcCity
LOCAL lnClientid
LOCAL lcCredit_noteCode
LOCAL lcCountry
LOCAL lcCreate_date
LOCAL lcCredit_number
LOCAL lcCredit_type
LOCAL lnCreditid
LOCAL lcCurrency_code
LOCAL lcCurrent_organization
LOCAL lcDescription
LOCAL lcDisplay_status
LOCAL lcDispute_status
LOCAL lnExt_archive
LOCAL lcFname
LOCAL lnId
LOCAL lcLanguage
LOCAL lcLast_order_status
LOCAL lcLname
LOCAL lcNotes
LOCAL lcOrganization
LOCAL lcPaidAmount
LOCAL lcPaidCode
LOCAL lcPayment_status
LOCAL lcProvince
LOCAL lnSentid
LOCAL lcStatus
LOCAL lcStreet
LOCAL lcStreet2
LOCAL lcTemplate
LOCAL lcTerms
LOCAL lcVat_name
LOCAL lcVat_number
LOCAL lnVis_state

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateInt("credit_note.vis_state",1)

* Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbRequestBody = CreateObject('Chilkat.StringBuilder')
loJson.EmitSb(loSbRequestBody)

loResp = loHttp.PTextSb("PUT","https://api.freshbooks.com/accounting/account/{{accountId}}/credit_notes/credit_notes/{{creditId}}",loSbRequestBody,"utf-8","application/json",0,0)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJson
    RELEASE loSbRequestBody
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    RELEASE loResp
    RELEASE loHttp
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

RELEASE loResp

* 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

lcAccounting_systemid = loJResp.StringOf("response.result.credit_note.accounting_systemid")
lcAmount = loJResp.StringOf("response.result.credit_note.amount.amount")
lcCode = loJResp.StringOf("response.result.credit_note.amount.code")
lcCity = loJResp.StringOf("response.result.credit_note.city")
lnClientid = loJResp.IntOf("response.result.credit_note.clientid")
lcCredit_noteCode = loJResp.StringOf("response.result.credit_note.code")
lcCountry = loJResp.StringOf("response.result.credit_note.country")
lcCreate_date = loJResp.StringOf("response.result.credit_note.create_date")
lcCredit_number = loJResp.StringOf("response.result.credit_note.credit_number")
lcCredit_type = loJResp.StringOf("response.result.credit_note.credit_type")
lnCreditid = loJResp.IntOf("response.result.credit_note.creditid")
lcCurrency_code = loJResp.StringOf("response.result.credit_note.currency_code")
lcCurrent_organization = loJResp.StringOf("response.result.credit_note.current_organization")
lcDescription = loJResp.StringOf("response.result.credit_note.description")
lcDisplay_status = loJResp.StringOf("response.result.credit_note.display_status")
lcDispute_status = loJResp.StringOf("response.result.credit_note.dispute_status")
lnExt_archive = loJResp.IntOf("response.result.credit_note.ext_archive")
lcFname = loJResp.StringOf("response.result.credit_note.fname")
lnId = loJResp.IntOf("response.result.credit_note.id")
lcLanguage = loJResp.StringOf("response.result.credit_note.language")
lcLast_order_status = loJResp.StringOf("response.result.credit_note.last_order_status")
lcLname = loJResp.StringOf("response.result.credit_note.lname")
lcNotes = loJResp.StringOf("response.result.credit_note.notes")
lcOrganization = loJResp.StringOf("response.result.credit_note.organization")
lcPaidAmount = loJResp.StringOf("response.result.credit_note.paid.amount")
lcPaidCode = loJResp.StringOf("response.result.credit_note.paid.code")
lcPayment_status = loJResp.StringOf("response.result.credit_note.payment_status")
lcProvince = loJResp.StringOf("response.result.credit_note.province")
lnSentid = loJResp.IntOf("response.result.credit_note.sentid")
lcStatus = loJResp.StringOf("response.result.credit_note.status")
lcStreet = loJResp.StringOf("response.result.credit_note.street")
lcStreet2 = loJResp.StringOf("response.result.credit_note.street2")
lcTemplate = loJResp.StringOf("response.result.credit_note.template")
lcTerms = loJResp.StringOf("response.result.credit_note.terms")
lcVat_name = loJResp.StringOf("response.result.credit_note.vat_name")
lcVat_number = loJResp.StringOf("response.result.credit_note.vat_number")
lnVis_state = loJResp.IntOf("response.result.credit_note.vis_state")

RELEASE loHttp
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp

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