Chilkat Online Tools

DataFlex / New FreshBooks / Delete Credit

Back to Collection Items

Use ChilkatAx-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 sAccounting_systemid
    String sAmount
    String sCode
    String sCity
    Integer iClientid
    String sCredit_noteCode
    String sCountry
    String sCreate_date
    String sCredit_number
    String sCredit_type
    Integer iCreditid
    String sCurrency_code
    String sCurrent_organization
    String sDescription
    String sDisplay_status
    String sDispute_status
    Integer iExt_archive
    String sFname
    Integer iId
    String sLanguage
    String sLast_order_status
    String sLname
    String sNotes
    String sOrganization
    String sPaidAmount
    String sPaidCode
    String sPayment_status
    String sProvince
    Integer iSentid
    String sStatus
    String sStreet
    String sStreet2
    String sTemplate
    String sTerms
    String sVat_name
    String sVat_number
    Integer iVis_state
    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.

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateInt Of hoJson "credit_note.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}}/credit_notes/credit_notes/{{creditId}}" 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": {
    //       "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

    Get ComStringOf Of hoJResp "response.result.credit_note.accounting_systemid" To sAccounting_systemid
    Get ComStringOf Of hoJResp "response.result.credit_note.amount.amount" To sAmount
    Get ComStringOf Of hoJResp "response.result.credit_note.amount.code" To sCode
    Get ComStringOf Of hoJResp "response.result.credit_note.city" To sCity
    Get ComIntOf Of hoJResp "response.result.credit_note.clientid" To iClientid
    Get ComStringOf Of hoJResp "response.result.credit_note.code" To sCredit_noteCode
    Get ComStringOf Of hoJResp "response.result.credit_note.country" To sCountry
    Get ComStringOf Of hoJResp "response.result.credit_note.create_date" To sCreate_date
    Get ComStringOf Of hoJResp "response.result.credit_note.credit_number" To sCredit_number
    Get ComStringOf Of hoJResp "response.result.credit_note.credit_type" To sCredit_type
    Get ComIntOf Of hoJResp "response.result.credit_note.creditid" To iCreditid
    Get ComStringOf Of hoJResp "response.result.credit_note.currency_code" To sCurrency_code
    Get ComStringOf Of hoJResp "response.result.credit_note.current_organization" To sCurrent_organization
    Get ComStringOf Of hoJResp "response.result.credit_note.description" To sDescription
    Get ComStringOf Of hoJResp "response.result.credit_note.display_status" To sDisplay_status
    Get ComStringOf Of hoJResp "response.result.credit_note.dispute_status" To sDispute_status
    Get ComIntOf Of hoJResp "response.result.credit_note.ext_archive" To iExt_archive
    Get ComStringOf Of hoJResp "response.result.credit_note.fname" To sFname
    Get ComIntOf Of hoJResp "response.result.credit_note.id" To iId
    Get ComStringOf Of hoJResp "response.result.credit_note.language" To sLanguage
    Get ComStringOf Of hoJResp "response.result.credit_note.last_order_status" To sLast_order_status
    Get ComStringOf Of hoJResp "response.result.credit_note.lname" To sLname
    Get ComStringOf Of hoJResp "response.result.credit_note.notes" To sNotes
    Get ComStringOf Of hoJResp "response.result.credit_note.organization" To sOrganization
    Get ComStringOf Of hoJResp "response.result.credit_note.paid.amount" To sPaidAmount
    Get ComStringOf Of hoJResp "response.result.credit_note.paid.code" To sPaidCode
    Get ComStringOf Of hoJResp "response.result.credit_note.payment_status" To sPayment_status
    Get ComStringOf Of hoJResp "response.result.credit_note.province" To sProvince
    Get ComIntOf Of hoJResp "response.result.credit_note.sentid" To iSentid
    Get ComStringOf Of hoJResp "response.result.credit_note.status" To sStatus
    Get ComStringOf Of hoJResp "response.result.credit_note.street" To sStreet
    Get ComStringOf Of hoJResp "response.result.credit_note.street2" To sStreet2
    Get ComStringOf Of hoJResp "response.result.credit_note.template" To sTemplate
    Get ComStringOf Of hoJResp "response.result.credit_note.terms" To sTerms
    Get ComStringOf Of hoJResp "response.result.credit_note.vat_name" To sVat_name
    Get ComStringOf Of hoJResp "response.result.credit_note.vat_number" To sVat_number
    Get ComIntOf Of hoJResp "response.result.credit_note.vis_state" To iVis_state


End_Procedure

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