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
(PureBasic) 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
IncludeFile "CkStringBuilder.pb" IncludeFile "CkRest.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; 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. jsonToken.i = CkJsonObject::ckCreate() If jsonToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/qb-access-token.json") rest.i = CkRest::ckCreate() If rest.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to the REST server. bTls.i = 1 port.i = 443 bAutoReconnect.i = 1 success.i = CkRest::ckConnect(rest,"sandbox-quickbooks.api.intuit.com",port,bTls,bAutoReconnect) sbAuth.i = CkStringBuilder::ckCreate() If sbAuth.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbAuth,"Bearer ") CkStringBuilder::ckAppend(sbAuth,CkJsonObject::ckStringOf(jsonToken,"access_token")) CkRest::setCkAuthorization(rest, CkStringBuilder::ckGetAsString(sbAuth)) ; -------------------------------------------------------------------------- ; 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???) CkRest::ckAddHeader(rest,"Content-Type","application/octet-stream") CkRest::setCkAllowHeaderFolding(rest, 0) sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkRest::ckFullRequestNoBodySb(rest,"POST","/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>",sbResponseBody) If success <> 1 Debug CkRest::ckLastErrorText(rest) CkJsonObject::ckDispose(jsonToken) CkRest::ckDispose(rest) CkStringBuilder::ckDispose(sbAuth) CkStringBuilder::ckDispose(sbResponseBody) ProcedureReturn EndIf respStatusCode.i = CkRest::ckResponseStatusCode(rest) ; Success is indicated by a 200 response status code. Debug "response status code = " + Str(respStatusCode) jsonResponse.i = CkJsonObject::ckCreate() If jsonResponse.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jsonResponse,sbResponseBody) CkJsonObject::setCkEmitCompact(jsonResponse, 0) Debug CkJsonObject::ckEmit(jsonResponse) If CkRest::ckResponseStatusCode(rest) <> 200 Debug "Failed." CkJsonObject::ckDispose(jsonToken) CkRest::ckDispose(rest) CkStringBuilder::ckDispose(sbAuth) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jsonResponse) ProcedureReturn 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" ; } ; Description.s DetailType.s SalesItemLineDetailTaxCodeRefValue.s SalesItemLineDetailQty.i SalesItemLineDetailUnitPrice.i SalesItemLineDetailServiceDate.s SalesItemLineDetailItemRefName.s SalesItemLineDetailItemRefValue.s LineNum.i Amount.s Id.s DiscountLineDetailDiscountAccountRefName.s DiscountLineDetailDiscountAccountRefValue.s DiscountLineDetailPercentBased.i DiscountLineDetailDiscountPercent.i TaxLineDetailNetAmountTaxable.s TaxLineDetailTaxPercent.i TaxLineDetailTaxRateRefValue.s TaxLineDetailPercentBased.i StringValue.s Type.s Name.s InvoiceTxnDate.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TxnDate") InvoiceDomain.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.domain") InvoiceCurrencyRefName.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.CurrencyRef.name") InvoiceCurrencyRefValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.CurrencyRef.value") InvoiceShipDate.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipDate") InvoiceTrackingNum.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TrackingNum") InvoiceClassRefName.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ClassRef.name") InvoiceClassRefValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ClassRef.value") InvoicePrintStatus.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.PrintStatus") InvoiceSalesTermRefValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.SalesTermRef.value") InvoiceDeliveryInfoDeliveryType.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.DeliveryInfo.DeliveryType") InvoiceDeliveryInfoDeliveryTime.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.DeliveryInfo.DeliveryTime") InvoiceTotalAmt.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TotalAmt") InvoiceDueDate.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.DueDate") InvoiceMetaDataCreateTime.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.MetaData.CreateTime") InvoiceMetaDataLastUpdatedTime.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.MetaData.LastUpdatedTime") InvoiceDocNumber.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.DocNumber") InvoicePrivateNote.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.PrivateNote") InvoiceSparse.i = CkJsonObject::ckBoolOf(jsonResponse,"Invoice.sparse") InvoiceDepositToAccountRefName.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.DepositToAccountRef.name") InvoiceDepositToAccountRefValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.DepositToAccountRef.value") InvoiceCustomerMemoValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.CustomerMemo.value") InvoiceEmailStatus.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.EmailStatus") InvoiceDeposit.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Deposit") InvoiceBalance.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Balance") InvoiceCustomerRefName.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.CustomerRef.name") InvoiceCustomerRefValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.CustomerRef.value") InvoiceTxnTaxDetailTxnTaxCodeRefValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TxnTaxDetail.TxnTaxCodeRef.value") InvoiceTxnTaxDetailTotalTax.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TxnTaxDetail.TotalTax") InvoiceSyncToken.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.SyncToken") InvoiceBillEmailAddress.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillEmail.Address") InvoiceShipAddrCity.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.City") InvoiceShipAddrCountry.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Country") InvoiceShipAddrLine5.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Line5") InvoiceShipAddrLine4.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Line4") InvoiceShipAddrLine3.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Line3") InvoiceShipAddrLine2.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Line2") InvoiceShipAddrLine1.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Line1") InvoiceShipAddrPostalCode.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.PostalCode") InvoiceShipAddrLat.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Lat") InvoiceShipAddrLong.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Long") InvoiceShipAddrCountrySubDivisionCode.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.CountrySubDivisionCode") InvoiceShipAddrId.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipAddr.Id") InvoiceDepartmentRefName.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.DepartmentRef.name") InvoiceDepartmentRefValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.DepartmentRef.value") InvoiceShipMethodRefName.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipMethodRef.name") InvoiceShipMethodRefValue.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.ShipMethodRef.value") InvoiceBillAddrCity.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.City") InvoiceBillAddrCountry.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Country") InvoiceBillAddrLine5.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Line5") InvoiceBillAddrLine4.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Line4") InvoiceBillAddrLine3.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Line3") InvoiceBillAddrLine2.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Line2") InvoiceBillAddrLine1.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Line1") InvoiceBillAddrPostalCode.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.PostalCode") InvoiceBillAddrLat.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Lat") InvoiceBillAddrLong.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Long") InvoiceBillAddrCountrySubDivisionCode.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.CountrySubDivisionCode") InvoiceBillAddrId.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.BillAddr.Id") InvoiceApplyTaxAfterDiscount.i = CkJsonObject::ckBoolOf(jsonResponse,"Invoice.ApplyTaxAfterDiscount") InvoiceId.s = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Id") time.s = CkJsonObject::ckStringOf(jsonResponse,"time") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jsonResponse,"Invoice.Line") While i < count_i CkJsonObject::setCkI(jsonResponse, i) Description = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].Description") DetailType = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].DetailType") SalesItemLineDetailTaxCodeRefValue = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value") SalesItemLineDetailQty = CkJsonObject::ckIntOf(jsonResponse,"Invoice.Line[i].SalesItemLineDetail.Qty") SalesItemLineDetailUnitPrice = CkJsonObject::ckIntOf(jsonResponse,"Invoice.Line[i].SalesItemLineDetail.UnitPrice") SalesItemLineDetailServiceDate = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].SalesItemLineDetail.ServiceDate") SalesItemLineDetailItemRefName = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].SalesItemLineDetail.ItemRef.name") SalesItemLineDetailItemRefValue = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].SalesItemLineDetail.ItemRef.value") LineNum = CkJsonObject::ckIntOf(jsonResponse,"Invoice.Line[i].LineNum") Amount = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].Amount") Id = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].Id") DiscountLineDetailDiscountAccountRefName = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.name") DiscountLineDetailDiscountAccountRefValue = CkJsonObject::ckStringOf(jsonResponse,"Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.value") DiscountLineDetailPercentBased = CkJsonObject::ckBoolOf(jsonResponse,"Invoice.Line[i].DiscountLineDetail.PercentBased") DiscountLineDetailDiscountPercent = CkJsonObject::ckIntOf(jsonResponse,"Invoice.Line[i].DiscountLineDetail.DiscountPercent") i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"Invoice.TxnTaxDetail.TaxLine") While i < count_i CkJsonObject::setCkI(jsonResponse, i) DetailType = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TxnTaxDetail.TaxLine[i].DetailType") Amount = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TxnTaxDetail.TaxLine[i].Amount") TaxLineDetailNetAmountTaxable = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable") TaxLineDetailTaxPercent = CkJsonObject::ckIntOf(jsonResponse,"Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent") TaxLineDetailTaxRateRefValue = CkJsonObject::ckStringOf(jsonResponse,"Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value") TaxLineDetailPercentBased = CkJsonObject::ckBoolOf(jsonResponse,"Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased") i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"Invoice.CustomField") While i < count_i CkJsonObject::setCkI(jsonResponse, i) StringValue = CkJsonObject::ckStringOf(jsonResponse,"Invoice.CustomField[i].StringValue") Type = CkJsonObject::ckStringOf(jsonResponse,"Invoice.CustomField[i].Type") Name = CkJsonObject::ckStringOf(jsonResponse,"Invoice.CustomField[i].Name") i = i + 1 Wend CkJsonObject::ckDispose(jsonToken) CkRest::ckDispose(rest) CkStringBuilder::ckDispose(sbAuth) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jsonResponse) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.