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
(DataFlex) Quickbooks Update an InvoiceDemonstrates how to update 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#full-update-an-invoice
Use ChilkatAx-win32.pkg Procedure Test Handle hoJsonToken Boolean iSuccess Handle hoRest Boolean iBTls Integer iPort Boolean iBAutoReconnect Boolean iSuccess Handle hoSbAuth Handle hoJsonReq Variant vSbRequestBody Handle hoSbRequestBody Variant vSbResponseBody Handle hoSbResponseBody Integer iRespStatusCode Handle hoJsonResponse Integer iLineNum String sAmount String sSalesItemLineDetailTaxCodeRefValue String sSalesItemLineDetailItemRefName String sSalesItemLineDetailItemRefValue String sId String sDetailType String sDefinitionId String sInvType String sName String sInvoiceTxnDate String sInvoiceDomain String sInvoicePrintStatus String sInvoiceTotalAmt String sInvoiceDueDate Boolean iInvoiceApplyTaxAfterDiscount String sInvoiceDocNumber Boolean iInvoiceSparse String sInvoiceCustomerMemoValue Integer iInvoiceDeposit String sInvoiceBalance String sInvoiceCustomerRefName String sInvoiceCustomerRefValue Integer iInvoiceTxnTaxDetailTotalTax String sInvoiceSyncToken String sInvoiceShipAddrCountrySubDivisionCode String sInvoiceShipAddrCity String sInvoiceShipAddrPostalCode String sInvoiceShipAddrId String sInvoiceShipAddrLine1 String sInvoiceEmailStatus String sInvoiceBillAddrCountrySubDivisionCode String sInvoiceBillAddrCity String sInvoiceBillAddrPostalCode String sInvoiceBillAddrId String sInvoiceBillAddrLine1 String sInvoiceMetaDataCreateTime String sInvoiceMetaDataLastUpdatedTime String sInvoiceId String sTime Integer i Integer iCount_i String sTemp1 Integer iTemp1 // 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: // { // "DocNumber": "1070", // "SyncToken": "0", // "domain": "QBO", // "Balance": 150.0, // "BillAddr": { // "City": "Bayshore", // "Line1": "4581 Finch St.", // "PostalCode": "94326", // "Lat": "INVALID", // "Long": "INVALID", // "CountrySubDivisionCode": "CA", // "Id": "2" // }, // "TxnDate": "2015-07-24", // "TotalAmt": 150.0, // "CustomerRef": { // "name": "Amy's Bird Sanctuary", // "value": "1" // }, // "CustomerMemo": { // "value": "Added customer memo." // }, // "ShipAddr": { // "City": "Bayshore", // "Line1": "4581 Finch St.", // "PostalCode": "94326", // "Lat": "INVALID", // "Long": "INVALID", // "CountrySubDivisionCode": "CA", // "Id": "109" // }, // "LinkedTxn": [ // ], // "DueDate": "2015-08-23", // "PrintStatus": "NeedToPrint", // "EmailStatus": "NotSet", // "sparse": false, // "Line": [ // { // "LineNum": 1, // "Amount": 150.0, // "SalesItemLineDetail": { // "TaxCodeRef": { // "value": "NON" // }, // "ItemRef": { // "name": "Services", // "value": "1" // } // }, // "Id": "1", // "DetailType": "SalesItemLineDetail" // }, // { // "DetailType": "SubTotalLineDetail", // "Amount": 150.0, // "SubTotalLineDetail": {} // } // ], // "ApplyTaxAfterDiscount": false, // "CustomField": [ // { // "DefinitionId": "1", // "Type": "StringType", // "Name": "Crew #" // } // ], // "Id": "239", // "TxnTaxDetail": { // "TotalTax": 0 // }, // "MetaData": { // "CreateTime": "2015-07-24T10:35:08-07:00", // "LastUpdatedTime": "2015-07-24T10:35:08-07:00" // } // } // // 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 "DocNumber" "1070" To iSuccess Get ComUpdateString Of hoJsonReq "SyncToken" "0" To iSuccess Get ComUpdateString Of hoJsonReq "domain" "QBO" To iSuccess Get ComUpdateNumber Of hoJsonReq "Balance" "150.0" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.City" "Bayshore" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.Line1" "4581 Finch St." To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.PostalCode" "94326" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.Lat" "INVALID" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.Long" "INVALID" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.CountrySubDivisionCode" "CA" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.Id" "2" To iSuccess Get ComUpdateString Of hoJsonReq "TxnDate" "2015-07-24" To iSuccess Get ComUpdateNumber Of hoJsonReq "TotalAmt" "150.0" To iSuccess Get ComUpdateString Of hoJsonReq "CustomerRef.name" "Amy's Bird Sanctuary" To iSuccess Get ComUpdateString Of hoJsonReq "CustomerRef.value" "1" To iSuccess Get ComUpdateString Of hoJsonReq "CustomerMemo.value" "Added customer memo." To iSuccess Get ComUpdateString Of hoJsonReq "ShipAddr.City" "Bayshore" To iSuccess Get ComUpdateString Of hoJsonReq "ShipAddr.Line1" "4581 Finch St." To iSuccess Get ComUpdateString Of hoJsonReq "ShipAddr.PostalCode" "94326" To iSuccess Get ComUpdateString Of hoJsonReq "ShipAddr.Lat" "INVALID" To iSuccess Get ComUpdateString Of hoJsonReq "ShipAddr.Long" "INVALID" To iSuccess Get ComUpdateString Of hoJsonReq "ShipAddr.CountrySubDivisionCode" "CA" To iSuccess Get ComUpdateString Of hoJsonReq "ShipAddr.Id" "109" To iSuccess Get ComUpdateNewArray Of hoJsonReq "LinkedTxn" To iSuccess Get ComUpdateString Of hoJsonReq "DueDate" "2015-08-23" To iSuccess Get ComUpdateString Of hoJsonReq "PrintStatus" "NeedToPrint" To iSuccess Get ComUpdateString Of hoJsonReq "EmailStatus" "NotSet" To iSuccess Get ComUpdateBool Of hoJsonReq "sparse" False To iSuccess Get ComUpdateInt Of hoJsonReq "Line[0].LineNum" 1 To iSuccess Get ComUpdateNumber Of hoJsonReq "Line[0].Amount" "150.0" To iSuccess Get ComUpdateString Of hoJsonReq "Line[0].SalesItemLineDetail.TaxCodeRef.value" "NON" To iSuccess Get ComUpdateString Of hoJsonReq "Line[0].SalesItemLineDetail.ItemRef.name" "Services" To iSuccess Get ComUpdateString Of hoJsonReq "Line[0].SalesItemLineDetail.ItemRef.value" "1" To iSuccess Get ComUpdateString Of hoJsonReq "Line[0].Id" "1" To iSuccess Get ComUpdateString Of hoJsonReq "Line[0].DetailType" "SalesItemLineDetail" To iSuccess Get ComUpdateString Of hoJsonReq "Line[1].DetailType" "SubTotalLineDetail" To iSuccess Get ComUpdateNumber Of hoJsonReq "Line[1].Amount" "150.0" To iSuccess Get ComUpdateNewObject Of hoJsonReq "Line[1].SubTotalLineDetail" To iSuccess Get ComUpdateBool Of hoJsonReq "ApplyTaxAfterDiscount" False To iSuccess Get ComUpdateString Of hoJsonReq "CustomField[0].DefinitionId" "1" To iSuccess Get ComUpdateString Of hoJsonReq "CustomField[0].Type" "StringType" To iSuccess Get ComUpdateString Of hoJsonReq "CustomField[0].Name" "Crew #" To iSuccess Get ComUpdateString Of hoJsonReq "Id" "239" To iSuccess Get ComUpdateInt Of hoJsonReq "TxnTaxDetail.TotalTax" 0 To iSuccess Get ComUpdateString Of hoJsonReq "MetaData.CreateTime" "2015-07-24T10:35:08-07:00" To iSuccess Get ComUpdateString Of hoJsonReq "MetaData.LastUpdatedTime" "2015-07-24T10:35:08-07:00" 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" 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": { // "TxnDate": "2015-07-24", // "domain": "QBO", // "PrintStatus": "NeedToPrint", // "TotalAmt": 150.0, // "Line": [ // { // "LineNum": 1, // "Amount": 150.0, // "SalesItemLineDetail": { // "TaxCodeRef": { // "value": "NON" // }, // "ItemRef": { // "name": "Services", // "value": "1" // } // }, // "Id": "1", // "DetailType": "SalesItemLineDetail" // }, // { // "DetailType": "SubTotalLineDetail", // "Amount": 150.0, // "SubTotalLineDetail": {} // } // ], // "DueDate": "2015-08-23", // "ApplyTaxAfterDiscount": false, // "DocNumber": "1070", // "sparse": false, // "CustomerMemo": { // "value": "Added customer memo." // }, // "Deposit": 0, // "Balance": 150.0, // "CustomerRef": { // "name": "Amy's Bird Sanctuary", // "value": "1" // }, // "TxnTaxDetail": { // "TotalTax": 0 // }, // "SyncToken": "1", // "LinkedTxn": [ // ], // "ShipAddr": { // "CountrySubDivisionCode": "CA", // "City": "Bayshore", // "PostalCode": "94326", // "Id": "118", // "Line1": "4581 Finch St." // }, // "EmailStatus": "NotSet", // "BillAddr": { // "CountrySubDivisionCode": "CA", // "City": "Bayshore", // "PostalCode": "94326", // "Id": "117", // "Line1": "4581 Finch St." // }, // "MetaData": { // "CreateTime": "2015-07-24T10:35:08-07:00", // "LastUpdatedTime": "2015-07-24T10:53:39-07:00" // }, // "CustomField": [ // { // "DefinitionId": "1", // "Type": "StringType", // "Name": "Crew #" // } // ], // "Id": "239" // }, // "time": "2015-07-24T10:53:39.287-07:00" // } // Get ComStringOf Of hoJsonResponse "Invoice.TxnDate" To sInvoiceTxnDate Get ComStringOf Of hoJsonResponse "Invoice.domain" To sInvoiceDomain Get ComStringOf Of hoJsonResponse "Invoice.PrintStatus" To sInvoicePrintStatus Get ComStringOf Of hoJsonResponse "Invoice.TotalAmt" To sInvoiceTotalAmt Get ComStringOf Of hoJsonResponse "Invoice.DueDate" To sInvoiceDueDate Get ComBoolOf Of hoJsonResponse "Invoice.ApplyTaxAfterDiscount" To iInvoiceApplyTaxAfterDiscount Get ComStringOf Of hoJsonResponse "Invoice.DocNumber" To sInvoiceDocNumber Get ComBoolOf Of hoJsonResponse "Invoice.sparse" To iInvoiceSparse Get ComStringOf Of hoJsonResponse "Invoice.CustomerMemo.value" To sInvoiceCustomerMemoValue Get ComIntOf Of hoJsonResponse "Invoice.Deposit" To iInvoiceDeposit 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 ComIntOf Of hoJsonResponse "Invoice.TxnTaxDetail.TotalTax" To iInvoiceTxnTaxDetailTotalTax Get ComStringOf Of hoJsonResponse "Invoice.SyncToken" To sInvoiceSyncToken Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.CountrySubDivisionCode" To sInvoiceShipAddrCountrySubDivisionCode Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.City" To sInvoiceShipAddrCity Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.PostalCode" To sInvoiceShipAddrPostalCode Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Id" To sInvoiceShipAddrId Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Line1" To sInvoiceShipAddrLine1 Get ComStringOf Of hoJsonResponse "Invoice.EmailStatus" To sInvoiceEmailStatus Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.CountrySubDivisionCode" To sInvoiceBillAddrCountrySubDivisionCode Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.City" To sInvoiceBillAddrCity Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.PostalCode" To sInvoiceBillAddrPostalCode Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Id" To sInvoiceBillAddrId Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Line1" To sInvoiceBillAddrLine1 Get ComStringOf Of hoJsonResponse "Invoice.MetaData.CreateTime" To sInvoiceMetaDataCreateTime Get ComStringOf Of hoJsonResponse "Invoice.MetaData.LastUpdatedTime" To sInvoiceMetaDataLastUpdatedTime 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 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].SalesItemLineDetail.TaxCodeRef.value" To sSalesItemLineDetailTaxCodeRefValue 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 ComStringOf Of hoJsonResponse "Invoice.Line[i].Id" To sId Get ComStringOf Of hoJsonResponse "Invoice.Line[i].DetailType" To sDetailType Move (i + 1) To i Loop Move 0 To i Get ComSizeOfArray Of hoJsonResponse "Invoice.LinkedTxn" To iCount_i While (i < iCount_i) Set ComI Of hoJsonResponse To i 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].DefinitionId" To sDefinitionId Get ComStringOf Of hoJsonResponse "Invoice.CustomField[i].Type" To sInvType Get ComStringOf Of hoJsonResponse "Invoice.CustomField[i].Name" To sName Move (i + 1) To i Loop End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.