DataFlex
DataFlex
Quickbooks Delete an Invoice
See more QuickBooks Examples
Demonstrates how to delete an invoice using the Quickbooks REST API.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoJsonToken
Handle hoRest
Boolean iBTls
Integer iPort
Boolean iBAutoReconnect
Handle hoSbAuth
Handle hoJsonReq
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vSbResponseBody
Handle hoSbResponseBody
Integer iRespStatusCode
Handle hoJsonResponse
String sInvoiceStatus
String sInvoiceDomain
String sInvoiceId
String sTime
String sTemp1
Integer iTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
If (Not(IsComObjectCreated(hoJsonToken))) Begin
Send CreateComObject of hoJsonToken
End
Get ComLoadFile Of hoJsonToken "qa_data/tokens/qb-access-token.json" To iSuccess
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// Connect to the REST server.
Move True To iBTls
Move 443 To iPort
Move True To iBAutoReconnect
Get ComConnect Of hoRest "sandbox-quickbooks.api.intuit.com" iPort iBTls iBAutoReconnect To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbAuth
If (Not(IsComObjectCreated(hoSbAuth))) Begin
Send CreateComObject of hoSbAuth
End
Get ComAppend Of hoSbAuth "Bearer " To iSuccess
Get ComStringOf Of hoJsonToken "access_token" To sTemp1
Get ComAppend Of hoSbAuth sTemp1 To iSuccess
Get ComGetAsString Of hoSbAuth To sTemp1
Set ComAuthorization Of hoRest To sTemp1
// --------------------------------------------------------------------------
// 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
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonReq
If (Not(IsComObjectCreated(hoJsonReq))) Begin
Send CreateComObject of hoJsonReq
End
Get ComUpdateString Of hoJsonReq "SyncToken" "3" To iSuccess
Get ComUpdateString Of hoJsonReq "Id" "33" To iSuccess
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 hoJsonReq vSbRequestBody To iSuccess
Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess
Get ComAddHeader Of hoRest "Accept" "application/json" To iSuccess
Set ComAllowHeaderFolding Of hoRest To False
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComFullRequestSb Of hoRest "POST" "/v3/company/<realmID>/invoice?operation=delete" vSbRequestBody vSbResponseBody To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iRespStatusCode
// Success is indicated by a 200 response status code.
Showln "response status code = " iRespStatusCode
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
If (Not(IsComObjectCreated(hoJsonResponse))) Begin
Send CreateComObject of hoJsonResponse
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJsonResponse To False
Get ComEmit Of hoJsonResponse To sTemp1
Showln sTemp1
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
Showln "Failed."
Procedure_Return
End
// 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"
// }
//
Get ComStringOf Of hoJsonResponse "Invoice.status" To sInvoiceStatus
Get ComStringOf Of hoJsonResponse "Invoice.domain" To sInvoiceDomain
Get ComStringOf Of hoJsonResponse "Invoice.Id" To sInvoiceId
Get ComStringOf Of hoJsonResponse "time" To sTime
End_Procedure