Sample code for 30+ languages & platforms
Visual FoxPro

Quickbooks Delete an Invoice

See more QuickBooks Examples

Demonstrates how to delete an invoice using the Quickbooks REST API.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loJsonToken
LOCAL loRest
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbAuth
LOCAL loJsonReq
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJsonResponse
LOCAL lcInvoiceStatus
LOCAL lcInvoiceDomain
LOCAL lcInvoiceId
LOCAL lcTime

lnSuccess = 0

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

* First get our previously obtained OAuth2 access token.
loJsonToken = CreateObject('Chilkat.JsonObject')
lnSuccess = loJsonToken.LoadFile("qa_data/tokens/qb-access-token.json")

loRest = CreateObject('Chilkat.Rest')

* Connect to the REST server.
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("sandbox-quickbooks.api.intuit.com",lnPort,lnBTls,lnBAutoReconnect)

loSbAuth = CreateObject('Chilkat.StringBuilder')
loSbAuth.Append("Bearer ")
loSbAuth.Append(loJsonToken.StringOf("access_token"))
loRest.Authorization = loSbAuth.GetAsString()

* --------------------------------------------------------------------------
* Note: The above code to setup the initial REST connection
* can be done once.  After connecting, any number of REST calls can be made.
* If the connection is lost, the next REST method call will automatically
* reconnect if needed.
* --------------------------------------------------------------------------

* Create the following JSON:

* {
*   "SyncToken": "3",
*   "Id": "33"
* }
* 
* Use the this online tool to generate the code from sample JSON: 
* Generate Code to Create JSON

loJsonReq = CreateObject('Chilkat.JsonObject')
loJsonReq.UpdateString("SyncToken","3")
loJsonReq.UpdateString("Id","33")

loSbRequestBody = CreateObject('Chilkat.StringBuilder')
loJsonReq.EmitSb(loSbRequestBody)

loRest.AddHeader("Content-Type","application/json")
loRest.AddHeader("Accept","application/json")
loRest.AllowHeaderFolding = 0

loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/v3/company/<realmID>/invoice?operation=delete",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loJsonToken
    RELEASE loRest
    RELEASE loSbAuth
    RELEASE loJsonReq
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode

* Success is indicated by a 200 response status code.
? "response status code = " + STR(lnRespStatusCode)

loJsonResponse = CreateObject('Chilkat.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)
loJsonResponse.EmitCompact = 0
? loJsonResponse.Emit()

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "Failed."
    RELEASE loJsonToken
    RELEASE loRest
    RELEASE loSbAuth
    RELEASE loJsonReq
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    RELEASE loJsonResponse
    CANCEL
ENDIF

* Sample output...
* (See the parsing code below..)
* 
* Use the this online tool to generate parsing code from sample JSON: 
* Generate Parsing Code from JSON

* {
*   "Invoice": {
*     "status": "Deleted",
*     "domain": "QBO",
*     "Id": "33"
*   },
*   "time": "2013-03-15T00:18:15.322-07:00"
* }
* 

lcInvoiceStatus = loJsonResponse.StringOf("Invoice.status")
lcInvoiceDomain = loJsonResponse.StringOf("Invoice.domain")
lcInvoiceId = loJsonResponse.StringOf("Invoice.Id")
lcTime = loJsonResponse.StringOf("time")

RELEASE loJsonToken
RELEASE loRest
RELEASE loSbAuth
RELEASE loJsonReq
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJsonResponse