DataFlex
DataFlex
Quickbooks Send an Invoice
See more QuickBooks Examples
Demonstrates how to send 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
Variant vSbResponseBody
Handle hoSbResponseBody
Integer iRespStatusCode
Handle hoJsonResponse
String sDescription
String sDetailType
String sSalesItemLineDetailTaxCodeRefValue
Integer iSalesItemLineDetailQty
Integer iSalesItemLineDetailUnitPrice
String sSalesItemLineDetailServiceDate
String sSalesItemLineDetailItemRefName
String sSalesItemLineDetailItemRefValue
Integer iLineNum
String sAmount
String sId
String sDiscountLineDetailDiscountAccountRefName
String sDiscountLineDetailDiscountAccountRefValue
Boolean iDiscountLineDetailPercentBased
Integer iDiscountLineDetailDiscountPercent
String sTaxLineDetailNetAmountTaxable
Integer iTaxLineDetailTaxPercent
String sTaxLineDetailTaxRateRefValue
Boolean iTaxLineDetailPercentBased
String sStringValue
String sType
String sName
String sInvoiceTxnDate
String sInvoiceDomain
String sInvoiceCurrencyRefName
String sInvoiceCurrencyRefValue
String sInvoiceShipDate
String sInvoiceTrackingNum
String sInvoiceClassRefName
String sInvoiceClassRefValue
String sInvoicePrintStatus
String sInvoiceSalesTermRefValue
String sInvoiceDeliveryInfoDeliveryType
String sInvoiceDeliveryInfoDeliveryTime
String sInvoiceTotalAmt
String sInvoiceDueDate
String sInvoiceMetaDataCreateTime
String sInvoiceMetaDataLastUpdatedTime
String sInvoiceDocNumber
String sInvoicePrivateNote
Boolean iInvoiceSparse
String sInvoiceDepositToAccountRefName
String sInvoiceDepositToAccountRefValue
String sInvoiceCustomerMemoValue
String sInvoiceEmailStatus
String sInvoiceDeposit
String sInvoiceBalance
String sInvoiceCustomerRefName
String sInvoiceCustomerRefValue
String sInvoiceTxnTaxDetailTxnTaxCodeRefValue
String sInvoiceTxnTaxDetailTotalTax
String sInvoiceSyncToken
String sInvoiceBillEmailAddress
String sInvoiceShipAddrCity
String sInvoiceShipAddrCountry
String sInvoiceShipAddrLine5
String sInvoiceShipAddrLine4
String sInvoiceShipAddrLine3
String sInvoiceShipAddrLine2
String sInvoiceShipAddrLine1
String sInvoiceShipAddrPostalCode
String sInvoiceShipAddrLat
String sInvoiceShipAddrLong
String sInvoiceShipAddrCountrySubDivisionCode
String sInvoiceShipAddrId
String sInvoiceDepartmentRefName
String sInvoiceDepartmentRefValue
String sInvoiceShipMethodRefName
String sInvoiceShipMethodRefValue
String sInvoiceBillAddrCity
String sInvoiceBillAddrCountry
String sInvoiceBillAddrLine5
String sInvoiceBillAddrLine4
String sInvoiceBillAddrLine3
String sInvoiceBillAddrLine2
String sInvoiceBillAddrLine1
String sInvoiceBillAddrPostalCode
String sInvoiceBillAddrLat
String sInvoiceBillAddrLong
String sInvoiceBillAddrCountrySubDivisionCode
String sInvoiceBillAddrId
Boolean iInvoiceApplyTaxAfterDiscount
String sInvoiceId
String sTime
Integer i
Integer iCount_i
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.
// --------------------------------------------------------------------------
// Technically, the POST has an empty request body, but the Quickbooks documentation indicates that
// the Content-Type header should be set to "application/octet-stream", which really makes no sense
// because there is not content. (How can no content have a type???)
Get ComAddHeader Of hoRest "Content-Type" "application/octet-stream" 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 hoSbResponseBody to vSbResponseBody
Get ComFullRequestNoBodySb Of hoRest "POST" "/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>" 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": {
// "TxnDate": "2013-03-14",
// "domain": "QBO",
// "CurrencyRef": {
// "name": "United States Dollar",
// "value": "USD"
// },
// "ShipDate": "2013-03-01",
// "TrackingNum": "123456789",
// "ClassRef": {
// "name": "Class 1",
// "value": "200900000000000003901"
// },
// "PrintStatus": "NeedToPrint",
// "SalesTermRef": {
// "value": "4"
// },
// "DeliveryInfo": {
// "DeliveryType": "Email",
// "DeliveryTime": "2014-12-17T11:50:52-08:00"
// },
// "TotalAmt": 52.0,
// "Line": [
// {
// "Description": "Sample invoice create request",
// "DetailType": "SalesItemLineDetail",
// "SalesItemLineDetail": {
// "TaxCodeRef": {
// "value": "TAX"
// },
// "Qty": 1,
// "UnitPrice": 50,
// "ServiceDate": "2013-03-04",
// "ItemRef": {
// "name": "Hours",
// "value": "2"
// }
// },
// "LineNum": 1,
// "Amount": 50.0,
// "Id": "1"
// },
// {
// "DetailType": "SubTotalLineDetail",
// "Amount": 50.0,
// "SubTotalLineDetail": {}
// },
// {
// "DetailType": "DiscountLineDetail",
// "Amount": 5.0,
// "DiscountLineDetail": {
// "DiscountAccountRef": {
// "name": "Discounts given",
// "value": "30"
// },
// "PercentBased": true,
// "DiscountPercent": 10
// }
// },
// {
// "DetailType": "SalesItemLineDetail",
// "Amount": 2.0,
// "SalesItemLineDetail": {
// "ItemRef": {
// "value": "SHIPPING_ITEM_ID"
// }
// }
// }
// ],
// "DueDate": "2013-05-13",
// "MetaData": {
// "CreateTime": "2013-03-14T01:42:16-07:00",
// "LastUpdatedTime": "2014-12-17T11:50:58-08:00"
// },
// "DocNumber": "Sample_Inv#2",
// "PrivateNote": "Summary for sample invoice",
// "sparse": false,
// "DepositToAccountRef": {
// "name": "Undeposited Funds",
// "value": "4"
// },
// "CustomerMemo": {
// "value": "This is the customer message"
// },
// "EmailStatus": "EmailSent",
// "Deposit": 12.0,
// "Balance": 40.0,
// "CustomerRef": {
// "name": "Mr V3 Service Customer Jr2",
// "value": "15"
// },
// "TxnTaxDetail": {
// "TxnTaxCodeRef": {
// "value": "5"
// },
// "TotalTax": 5.0,
// "TaxLine": [
// {
// "DetailType": "TaxLineDetail",
// "Amount": 5.0,
// "TaxLineDetail": {
// "NetAmountTaxable": 50.0,
// "TaxPercent": 10,
// "TaxRateRef": {
// "value": "2"
// },
// "PercentBased": true
// }
// }
// ]
// },
// "SyncToken": "0",
// "BillEmail": {
// "Address": "test@intuit.com"
// },
// "ShipAddr": {
// "City": "San Jose",
// "Country": "USA",
// "Line5": "Cube 999",
// "Line4": "Dept 12",
// "Line3": "123 street",
// "Line2": "Building 1",
// "Line1": "Intuit",
// "PostalCode": "95123",
// "Lat": "37.2374847",
// "Long": "-121.8277925",
// "CountrySubDivisionCode": "CA",
// "Id": "36"
// },
// "DepartmentRef": {
// "name": "Mountain View",
// "value": "1"
// },
// "ShipMethodRef": {
// "name": "UPS",
// "value": "UPS"
// },
// "BillAddr": {
// "City": "Mountain View",
// "Country": "USA",
// "Line5": "Cube 999",
// "Line4": "Dept 12",
// "Line3": "123 street",
// "Line2": "Building 1",
// "Line1": "Google",
// "PostalCode": "95123",
// "Lat": "37.2374847",
// "Long": "-121.8277925",
// "CountrySubDivisionCode": "CA",
// "Id": "35"
// },
// "ApplyTaxAfterDiscount": false,
// "CustomField": [
// {
// "StringValue": "Custom1",
// "Type": "StringType",
// "Name": "Custom 1"
// },
// {
// "StringValue": "Custom2",
// "Type": "StringType",
// "Name": "Custom 2"
// },
// {
// "StringValue": "Custom3",
// "Type": "StringType",
// "Name": "Custom 3"
// }
// ],
// "Id": "96"
// },
// "time": "2013-03-14T13:32:04.895-07:00"
// }
//
Get ComStringOf Of hoJsonResponse "Invoice.TxnDate" To sInvoiceTxnDate
Get ComStringOf Of hoJsonResponse "Invoice.domain" To sInvoiceDomain
Get ComStringOf Of hoJsonResponse "Invoice.CurrencyRef.name" To sInvoiceCurrencyRefName
Get ComStringOf Of hoJsonResponse "Invoice.CurrencyRef.value" To sInvoiceCurrencyRefValue
Get ComStringOf Of hoJsonResponse "Invoice.ShipDate" To sInvoiceShipDate
Get ComStringOf Of hoJsonResponse "Invoice.TrackingNum" To sInvoiceTrackingNum
Get ComStringOf Of hoJsonResponse "Invoice.ClassRef.name" To sInvoiceClassRefName
Get ComStringOf Of hoJsonResponse "Invoice.ClassRef.value" To sInvoiceClassRefValue
Get ComStringOf Of hoJsonResponse "Invoice.PrintStatus" To sInvoicePrintStatus
Get ComStringOf Of hoJsonResponse "Invoice.SalesTermRef.value" To sInvoiceSalesTermRefValue
Get ComStringOf Of hoJsonResponse "Invoice.DeliveryInfo.DeliveryType" To sInvoiceDeliveryInfoDeliveryType
Get ComStringOf Of hoJsonResponse "Invoice.DeliveryInfo.DeliveryTime" To sInvoiceDeliveryInfoDeliveryTime
Get ComStringOf Of hoJsonResponse "Invoice.TotalAmt" To sInvoiceTotalAmt
Get ComStringOf Of hoJsonResponse "Invoice.DueDate" To sInvoiceDueDate
Get ComStringOf Of hoJsonResponse "Invoice.MetaData.CreateTime" To sInvoiceMetaDataCreateTime
Get ComStringOf Of hoJsonResponse "Invoice.MetaData.LastUpdatedTime" To sInvoiceMetaDataLastUpdatedTime
Get ComStringOf Of hoJsonResponse "Invoice.DocNumber" To sInvoiceDocNumber
Get ComStringOf Of hoJsonResponse "Invoice.PrivateNote" To sInvoicePrivateNote
Get ComBoolOf Of hoJsonResponse "Invoice.sparse" To iInvoiceSparse
Get ComStringOf Of hoJsonResponse "Invoice.DepositToAccountRef.name" To sInvoiceDepositToAccountRefName
Get ComStringOf Of hoJsonResponse "Invoice.DepositToAccountRef.value" To sInvoiceDepositToAccountRefValue
Get ComStringOf Of hoJsonResponse "Invoice.CustomerMemo.value" To sInvoiceCustomerMemoValue
Get ComStringOf Of hoJsonResponse "Invoice.EmailStatus" To sInvoiceEmailStatus
Get ComStringOf Of hoJsonResponse "Invoice.Deposit" To sInvoiceDeposit
Get ComStringOf Of hoJsonResponse "Invoice.Balance" To sInvoiceBalance
Get ComStringOf Of hoJsonResponse "Invoice.CustomerRef.name" To sInvoiceCustomerRefName
Get ComStringOf Of hoJsonResponse "Invoice.CustomerRef.value" To sInvoiceCustomerRefValue
Get ComStringOf Of hoJsonResponse "Invoice.TxnTaxDetail.TxnTaxCodeRef.value" To sInvoiceTxnTaxDetailTxnTaxCodeRefValue
Get ComStringOf Of hoJsonResponse "Invoice.TxnTaxDetail.TotalTax" To sInvoiceTxnTaxDetailTotalTax
Get ComStringOf Of hoJsonResponse "Invoice.SyncToken" To sInvoiceSyncToken
Get ComStringOf Of hoJsonResponse "Invoice.BillEmail.Address" To sInvoiceBillEmailAddress
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.City" To sInvoiceShipAddrCity
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Country" To sInvoiceShipAddrCountry
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Line5" To sInvoiceShipAddrLine5
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Line4" To sInvoiceShipAddrLine4
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Line3" To sInvoiceShipAddrLine3
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Line2" To sInvoiceShipAddrLine2
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Line1" To sInvoiceShipAddrLine1
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.PostalCode" To sInvoiceShipAddrPostalCode
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Lat" To sInvoiceShipAddrLat
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Long" To sInvoiceShipAddrLong
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.CountrySubDivisionCode" To sInvoiceShipAddrCountrySubDivisionCode
Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Id" To sInvoiceShipAddrId
Get ComStringOf Of hoJsonResponse "Invoice.DepartmentRef.name" To sInvoiceDepartmentRefName
Get ComStringOf Of hoJsonResponse "Invoice.DepartmentRef.value" To sInvoiceDepartmentRefValue
Get ComStringOf Of hoJsonResponse "Invoice.ShipMethodRef.name" To sInvoiceShipMethodRefName
Get ComStringOf Of hoJsonResponse "Invoice.ShipMethodRef.value" To sInvoiceShipMethodRefValue
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.City" To sInvoiceBillAddrCity
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Country" To sInvoiceBillAddrCountry
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Line5" To sInvoiceBillAddrLine5
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Line4" To sInvoiceBillAddrLine4
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Line3" To sInvoiceBillAddrLine3
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Line2" To sInvoiceBillAddrLine2
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Line1" To sInvoiceBillAddrLine1
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.PostalCode" To sInvoiceBillAddrPostalCode
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Lat" To sInvoiceBillAddrLat
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Long" To sInvoiceBillAddrLong
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.CountrySubDivisionCode" To sInvoiceBillAddrCountrySubDivisionCode
Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Id" To sInvoiceBillAddrId
Get ComBoolOf Of hoJsonResponse "Invoice.ApplyTaxAfterDiscount" To iInvoiceApplyTaxAfterDiscount
Get ComStringOf Of hoJsonResponse "Invoice.Id" To sInvoiceId
Get ComStringOf Of hoJsonResponse "time" To sTime
Move 0 To i
Get ComSizeOfArray Of hoJsonResponse "Invoice.Line" To iCount_i
While (i < iCount_i)
Set ComI Of hoJsonResponse To i
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].Description" To sDescription
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].DetailType" To sDetailType
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value" To sSalesItemLineDetailTaxCodeRefValue
Get ComIntOf Of hoJsonResponse "Invoice.Line[i].SalesItemLineDetail.Qty" To iSalesItemLineDetailQty
Get ComIntOf Of hoJsonResponse "Invoice.Line[i].SalesItemLineDetail.UnitPrice" To iSalesItemLineDetailUnitPrice
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].SalesItemLineDetail.ServiceDate" To sSalesItemLineDetailServiceDate
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].SalesItemLineDetail.ItemRef.name" To sSalesItemLineDetailItemRefName
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].SalesItemLineDetail.ItemRef.value" To sSalesItemLineDetailItemRefValue
Get ComIntOf Of hoJsonResponse "Invoice.Line[i].LineNum" To iLineNum
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].Amount" To sAmount
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].Id" To sId
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.name" To sDiscountLineDetailDiscountAccountRefName
Get ComStringOf Of hoJsonResponse "Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.value" To sDiscountLineDetailDiscountAccountRefValue
Get ComBoolOf Of hoJsonResponse "Invoice.Line[i].DiscountLineDetail.PercentBased" To iDiscountLineDetailPercentBased
Get ComIntOf Of hoJsonResponse "Invoice.Line[i].DiscountLineDetail.DiscountPercent" To iDiscountLineDetailDiscountPercent
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJsonResponse "Invoice.TxnTaxDetail.TaxLine" To iCount_i
While (i < iCount_i)
Set ComI Of hoJsonResponse To i
Get ComStringOf Of hoJsonResponse "Invoice.TxnTaxDetail.TaxLine[i].DetailType" To sDetailType
Get ComStringOf Of hoJsonResponse "Invoice.TxnTaxDetail.TaxLine[i].Amount" To sAmount
Get ComStringOf Of hoJsonResponse "Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable" To sTaxLineDetailNetAmountTaxable
Get ComIntOf Of hoJsonResponse "Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent" To iTaxLineDetailTaxPercent
Get ComStringOf Of hoJsonResponse "Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value" To sTaxLineDetailTaxRateRefValue
Get ComBoolOf Of hoJsonResponse "Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased" To iTaxLineDetailPercentBased
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJsonResponse "Invoice.CustomField" To iCount_i
While (i < iCount_i)
Set ComI Of hoJsonResponse To i
Get ComStringOf Of hoJsonResponse "Invoice.CustomField[i].StringValue" To sStringValue
Get ComStringOf Of hoJsonResponse "Invoice.CustomField[i].Type" To sType
Get ComStringOf Of hoJsonResponse "Invoice.CustomField[i].Name" To sName
Move (i + 1) To i
Loop
End_Procedure