Sample code for 30+ languages & platforms
PowerBuilder

Quickbooks Delete an Invoice

See more QuickBooks Examples

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

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_JsonToken
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbAuth
oleobject loo_JsonReq
oleobject loo_SbRequestBody
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
string ls_InvoiceStatus
string ls_InvoiceDomain
string ls_InvoiceId
string ls_Time

li_Success = 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.
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_JsonToken
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_JsonToken.LoadFile("qa_data/tokens/qb-access-token.json")

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

// Connect to the REST server.
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("sandbox-quickbooks.api.intuit.com",li_Port,li_BTls,li_BAutoReconnect)

loo_SbAuth = create oleobject
li_rc = loo_SbAuth.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbAuth.Append("Bearer ")
loo_SbAuth.Append(loo_JsonToken.StringOf("access_token"))
loo_Rest.Authorization = loo_SbAuth.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

loo_JsonReq = create oleobject
li_rc = loo_JsonReq.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonReq.UpdateString("SyncToken","3")
loo_JsonReq.UpdateString("Id","33")

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_JsonReq.EmitSb(loo_SbRequestBody)

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

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Rest.FullRequestSb("POST","/v3/company/<realmID>/invoice?operation=delete",loo_SbRequestBody,loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_JsonToken
    destroy loo_Rest
    destroy loo_SbAuth
    destroy loo_JsonReq
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if

li_RespStatusCode = loo_Rest.ResponseStatusCode

// Success is indicated by a 200 response status code.
Write-Debug "response status code = " + string(li_RespStatusCode)

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonResponse.LoadSb(loo_SbResponseBody)
loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.Emit()

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "Failed."
    destroy loo_JsonToken
    destroy loo_Rest
    destroy loo_SbAuth
    destroy loo_JsonReq
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    destroy loo_JsonResponse
    return
end if

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

ls_InvoiceStatus = loo_JsonResponse.StringOf("Invoice.status")
ls_InvoiceDomain = loo_JsonResponse.StringOf("Invoice.domain")
ls_InvoiceId = loo_JsonResponse.StringOf("Invoice.Id")
ls_Time = loo_JsonResponse.StringOf("time")


destroy loo_JsonToken
destroy loo_Rest
destroy loo_SbAuth
destroy loo_JsonReq
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JsonResponse