Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Visual FoxPro) Quickbooks Send an InvoiceDemonstrates how to send an invoice using the Quickbooks REST API. For more information, see https://www.developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/invoice#send-an-invoice
LOCAL loJsonToken LOCAL lnSuccess LOCAL loRest LOCAL lnBTls LOCAL lnPort LOCAL lnBAutoReconnect LOCAL lnSuccess LOCAL loSbAuth LOCAL loSbResponseBody LOCAL lnRespStatusCode LOCAL loJsonResponse LOCAL lcDescription LOCAL lcDetailType LOCAL lcSalesItemLineDetailTaxCodeRefValue LOCAL lnSalesItemLineDetailQty LOCAL lnSalesItemLineDetailUnitPrice LOCAL lcSalesItemLineDetailServiceDate LOCAL lcSalesItemLineDetailItemRefName LOCAL lcSalesItemLineDetailItemRefValue LOCAL lnLineNum LOCAL lcAmount LOCAL lcId LOCAL lcDiscountLineDetailDiscountAccountRefName LOCAL lcDiscountLineDetailDiscountAccountRefValue LOCAL lnDiscountLineDetailPercentBased LOCAL lnDiscountLineDetailDiscountPercent LOCAL lcTaxLineDetailNetAmountTaxable LOCAL lnTaxLineDetailTaxPercent LOCAL lcTaxLineDetailTaxRateRefValue LOCAL lnTaxLineDetailPercentBased LOCAL lcStringValue LOCAL lcType LOCAL lcName LOCAL lcInvoiceTxnDate LOCAL lcInvoiceDomain LOCAL lcInvoiceCurrencyRefName LOCAL lcInvoiceCurrencyRefValue LOCAL lcInvoiceShipDate LOCAL lcInvoiceTrackingNum LOCAL lcInvoiceClassRefName LOCAL lcInvoiceClassRefValue LOCAL lcInvoicePrintStatus LOCAL lcInvoiceSalesTermRefValue LOCAL lcInvoiceDeliveryInfoDeliveryType LOCAL lcInvoiceDeliveryInfoDeliveryTime LOCAL lcInvoiceTotalAmt LOCAL lcInvoiceDueDate LOCAL lcInvoiceMetaDataCreateTime LOCAL lcInvoiceMetaDataLastUpdatedTime LOCAL lcInvoiceDocNumber LOCAL lcInvoicePrivateNote LOCAL lnInvoiceSparse LOCAL lcInvoiceDepositToAccountRefName LOCAL lcInvoiceDepositToAccountRefValue LOCAL lcInvoiceCustomerMemoValue LOCAL lcInvoiceEmailStatus LOCAL lcInvoiceDeposit LOCAL lcInvoiceBalance LOCAL lcInvoiceCustomerRefName LOCAL lcInvoiceCustomerRefValue LOCAL lcInvoiceTxnTaxDetailTxnTaxCodeRefValue LOCAL lcInvoiceTxnTaxDetailTotalTax LOCAL lcInvoiceSyncToken LOCAL lcInvoiceBillEmailAddress LOCAL lcInvoiceShipAddrCity LOCAL lcInvoiceShipAddrCountry LOCAL lcInvoiceShipAddrLine5 LOCAL lcInvoiceShipAddrLine4 LOCAL lcInvoiceShipAddrLine3 LOCAL lcInvoiceShipAddrLine2 LOCAL lcInvoiceShipAddrLine1 LOCAL lcInvoiceShipAddrPostalCode LOCAL lcInvoiceShipAddrLat LOCAL lcInvoiceShipAddrLong LOCAL lcInvoiceShipAddrCountrySubDivisionCode LOCAL lcInvoiceShipAddrId LOCAL lcInvoiceDepartmentRefName LOCAL lcInvoiceDepartmentRefValue LOCAL lcInvoiceShipMethodRefName LOCAL lcInvoiceShipMethodRefValue LOCAL lcInvoiceBillAddrCity LOCAL lcInvoiceBillAddrCountry LOCAL lcInvoiceBillAddrLine5 LOCAL lcInvoiceBillAddrLine4 LOCAL lcInvoiceBillAddrLine3 LOCAL lcInvoiceBillAddrLine2 LOCAL lcInvoiceBillAddrLine1 LOCAL lcInvoiceBillAddrPostalCode LOCAL lcInvoiceBillAddrLat LOCAL lcInvoiceBillAddrLong LOCAL lcInvoiceBillAddrCountrySubDivisionCode LOCAL lcInvoiceBillAddrId LOCAL lnInvoiceApplyTaxAfterDiscount LOCAL lcInvoiceId LOCAL lcTime LOCAL i LOCAL lnCount_i * 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. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJsonToken = CreateObject('Chilkat.JsonObject') lnSuccess = loJsonToken.LoadFile("qa_data/tokens/qb-access-token.json") * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Rest') 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) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') 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. * -------------------------------------------------------------------------- * 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???) loRest.AddHeader("Content-Type","application/octet-stream") loRest.AllowHeaderFolding = 0 * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbResponseBody = CreateObject('Chilkat.StringBuilder') lnSuccess = loRest.FullRequestNoBodySb("POST","/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>",loSbResponseBody) IF (lnSuccess <> 1) THEN ? loRest.LastErrorText RELEASE loJsonToken RELEASE loRest RELEASE loSbAuth RELEASE loSbResponseBody CANCEL ENDIF lnRespStatusCode = loRest.ResponseStatusCode * Success is indicated by a 200 response status code. ? "response status code = " + STR(lnRespStatusCode) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') 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 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": { * "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" * } * lcInvoiceTxnDate = loJsonResponse.StringOf("Invoice.TxnDate") lcInvoiceDomain = loJsonResponse.StringOf("Invoice.domain") lcInvoiceCurrencyRefName = loJsonResponse.StringOf("Invoice.CurrencyRef.name") lcInvoiceCurrencyRefValue = loJsonResponse.StringOf("Invoice.CurrencyRef.value") lcInvoiceShipDate = loJsonResponse.StringOf("Invoice.ShipDate") lcInvoiceTrackingNum = loJsonResponse.StringOf("Invoice.TrackingNum") lcInvoiceClassRefName = loJsonResponse.StringOf("Invoice.ClassRef.name") lcInvoiceClassRefValue = loJsonResponse.StringOf("Invoice.ClassRef.value") lcInvoicePrintStatus = loJsonResponse.StringOf("Invoice.PrintStatus") lcInvoiceSalesTermRefValue = loJsonResponse.StringOf("Invoice.SalesTermRef.value") lcInvoiceDeliveryInfoDeliveryType = loJsonResponse.StringOf("Invoice.DeliveryInfo.DeliveryType") lcInvoiceDeliveryInfoDeliveryTime = loJsonResponse.StringOf("Invoice.DeliveryInfo.DeliveryTime") lcInvoiceTotalAmt = loJsonResponse.StringOf("Invoice.TotalAmt") lcInvoiceDueDate = loJsonResponse.StringOf("Invoice.DueDate") lcInvoiceMetaDataCreateTime = loJsonResponse.StringOf("Invoice.MetaData.CreateTime") lcInvoiceMetaDataLastUpdatedTime = loJsonResponse.StringOf("Invoice.MetaData.LastUpdatedTime") lcInvoiceDocNumber = loJsonResponse.StringOf("Invoice.DocNumber") lcInvoicePrivateNote = loJsonResponse.StringOf("Invoice.PrivateNote") lnInvoiceSparse = loJsonResponse.BoolOf("Invoice.sparse") lcInvoiceDepositToAccountRefName = loJsonResponse.StringOf("Invoice.DepositToAccountRef.name") lcInvoiceDepositToAccountRefValue = loJsonResponse.StringOf("Invoice.DepositToAccountRef.value") lcInvoiceCustomerMemoValue = loJsonResponse.StringOf("Invoice.CustomerMemo.value") lcInvoiceEmailStatus = loJsonResponse.StringOf("Invoice.EmailStatus") lcInvoiceDeposit = loJsonResponse.StringOf("Invoice.Deposit") lcInvoiceBalance = loJsonResponse.StringOf("Invoice.Balance") lcInvoiceCustomerRefName = loJsonResponse.StringOf("Invoice.CustomerRef.name") lcInvoiceCustomerRefValue = loJsonResponse.StringOf("Invoice.CustomerRef.value") lcInvoiceTxnTaxDetailTxnTaxCodeRefValue = loJsonResponse.StringOf("Invoice.TxnTaxDetail.TxnTaxCodeRef.value") lcInvoiceTxnTaxDetailTotalTax = loJsonResponse.StringOf("Invoice.TxnTaxDetail.TotalTax") lcInvoiceSyncToken = loJsonResponse.StringOf("Invoice.SyncToken") lcInvoiceBillEmailAddress = loJsonResponse.StringOf("Invoice.BillEmail.Address") lcInvoiceShipAddrCity = loJsonResponse.StringOf("Invoice.ShipAddr.City") lcInvoiceShipAddrCountry = loJsonResponse.StringOf("Invoice.ShipAddr.Country") lcInvoiceShipAddrLine5 = loJsonResponse.StringOf("Invoice.ShipAddr.Line5") lcInvoiceShipAddrLine4 = loJsonResponse.StringOf("Invoice.ShipAddr.Line4") lcInvoiceShipAddrLine3 = loJsonResponse.StringOf("Invoice.ShipAddr.Line3") lcInvoiceShipAddrLine2 = loJsonResponse.StringOf("Invoice.ShipAddr.Line2") lcInvoiceShipAddrLine1 = loJsonResponse.StringOf("Invoice.ShipAddr.Line1") lcInvoiceShipAddrPostalCode = loJsonResponse.StringOf("Invoice.ShipAddr.PostalCode") lcInvoiceShipAddrLat = loJsonResponse.StringOf("Invoice.ShipAddr.Lat") lcInvoiceShipAddrLong = loJsonResponse.StringOf("Invoice.ShipAddr.Long") lcInvoiceShipAddrCountrySubDivisionCode = loJsonResponse.StringOf("Invoice.ShipAddr.CountrySubDivisionCode") lcInvoiceShipAddrId = loJsonResponse.StringOf("Invoice.ShipAddr.Id") lcInvoiceDepartmentRefName = loJsonResponse.StringOf("Invoice.DepartmentRef.name") lcInvoiceDepartmentRefValue = loJsonResponse.StringOf("Invoice.DepartmentRef.value") lcInvoiceShipMethodRefName = loJsonResponse.StringOf("Invoice.ShipMethodRef.name") lcInvoiceShipMethodRefValue = loJsonResponse.StringOf("Invoice.ShipMethodRef.value") lcInvoiceBillAddrCity = loJsonResponse.StringOf("Invoice.BillAddr.City") lcInvoiceBillAddrCountry = loJsonResponse.StringOf("Invoice.BillAddr.Country") lcInvoiceBillAddrLine5 = loJsonResponse.StringOf("Invoice.BillAddr.Line5") lcInvoiceBillAddrLine4 = loJsonResponse.StringOf("Invoice.BillAddr.Line4") lcInvoiceBillAddrLine3 = loJsonResponse.StringOf("Invoice.BillAddr.Line3") lcInvoiceBillAddrLine2 = loJsonResponse.StringOf("Invoice.BillAddr.Line2") lcInvoiceBillAddrLine1 = loJsonResponse.StringOf("Invoice.BillAddr.Line1") lcInvoiceBillAddrPostalCode = loJsonResponse.StringOf("Invoice.BillAddr.PostalCode") lcInvoiceBillAddrLat = loJsonResponse.StringOf("Invoice.BillAddr.Lat") lcInvoiceBillAddrLong = loJsonResponse.StringOf("Invoice.BillAddr.Long") lcInvoiceBillAddrCountrySubDivisionCode = loJsonResponse.StringOf("Invoice.BillAddr.CountrySubDivisionCode") lcInvoiceBillAddrId = loJsonResponse.StringOf("Invoice.BillAddr.Id") lnInvoiceApplyTaxAfterDiscount = loJsonResponse.BoolOf("Invoice.ApplyTaxAfterDiscount") lcInvoiceId = loJsonResponse.StringOf("Invoice.Id") lcTime = loJsonResponse.StringOf("time") i = 0 lnCount_i = loJsonResponse.SizeOfArray("Invoice.Line") DO WHILE i < lnCount_i loJsonResponse.I = i lcDescription = loJsonResponse.StringOf("Invoice.Line[i].Description") lcDetailType = loJsonResponse.StringOf("Invoice.Line[i].DetailType") lcSalesItemLineDetailTaxCodeRefValue = loJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value") lnSalesItemLineDetailQty = loJsonResponse.IntOf("Invoice.Line[i].SalesItemLineDetail.Qty") lnSalesItemLineDetailUnitPrice = loJsonResponse.IntOf("Invoice.Line[i].SalesItemLineDetail.UnitPrice") lcSalesItemLineDetailServiceDate = loJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ServiceDate") lcSalesItemLineDetailItemRefName = loJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.name") lcSalesItemLineDetailItemRefValue = loJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.value") lnLineNum = loJsonResponse.IntOf("Invoice.Line[i].LineNum") lcAmount = loJsonResponse.StringOf("Invoice.Line[i].Amount") lcId = loJsonResponse.StringOf("Invoice.Line[i].Id") lcDiscountLineDetailDiscountAccountRefName = loJsonResponse.StringOf("Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.name") lcDiscountLineDetailDiscountAccountRefValue = loJsonResponse.StringOf("Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.value") lnDiscountLineDetailPercentBased = loJsonResponse.BoolOf("Invoice.Line[i].DiscountLineDetail.PercentBased") lnDiscountLineDetailDiscountPercent = loJsonResponse.IntOf("Invoice.Line[i].DiscountLineDetail.DiscountPercent") i = i + 1 ENDDO i = 0 lnCount_i = loJsonResponse.SizeOfArray("Invoice.TxnTaxDetail.TaxLine") DO WHILE i < lnCount_i loJsonResponse.I = i lcDetailType = loJsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].DetailType") lcAmount = loJsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].Amount") lcTaxLineDetailNetAmountTaxable = loJsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable") lnTaxLineDetailTaxPercent = loJsonResponse.IntOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent") lcTaxLineDetailTaxRateRefValue = loJsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value") lnTaxLineDetailPercentBased = loJsonResponse.BoolOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased") i = i + 1 ENDDO i = 0 lnCount_i = loJsonResponse.SizeOfArray("Invoice.CustomField") DO WHILE i < lnCount_i loJsonResponse.I = i lcStringValue = loJsonResponse.StringOf("Invoice.CustomField[i].StringValue") lcType = loJsonResponse.StringOf("Invoice.CustomField[i].Type") lcName = loJsonResponse.StringOf("Invoice.CustomField[i].Name") i = i + 1 ENDDO RELEASE loJsonToken RELEASE loRest RELEASE loSbAuth RELEASE loSbResponseBody RELEASE loJsonResponse |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.