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
(PowerBuilder) 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
integer li_rc oleobject loo_JsonToken integer li_Success oleobject loo_Rest integer li_BTls integer li_Port integer li_BAutoReconnect integer li_Success oleobject loo_SbAuth oleobject loo_JsonReq oleobject loo_SbRequestBody oleobject loo_SbResponseBody integer li_RespStatusCode oleobject loo_JsonResponse integer li_LineNum string ls_Amount string ls_SalesItemLineDetailTaxCodeRefValue string ls_SalesItemLineDetailItemRefName string ls_SalesItemLineDetailItemRefValue string ls_Id string ls_DetailType string ls_DefinitionId string ls_InvType string ls_Name string ls_InvoiceTxnDate string ls_InvoiceDomain string ls_InvoicePrintStatus string ls_InvoiceTotalAmt string ls_InvoiceDueDate integer li_InvoiceApplyTaxAfterDiscount string ls_InvoiceDocNumber integer li_InvoiceSparse string ls_InvoiceCustomerMemoValue integer li_InvoiceDeposit string ls_InvoiceBalance string ls_InvoiceCustomerRefName string ls_InvoiceCustomerRefValue integer li_InvoiceTxnTaxDetailTotalTax string ls_InvoiceSyncToken string ls_InvoiceShipAddrCountrySubDivisionCode string ls_InvoiceShipAddrCity string ls_InvoiceShipAddrPostalCode string ls_InvoiceShipAddrId string ls_InvoiceShipAddrLine1 string ls_InvoiceEmailStatus string ls_InvoiceBillAddrCountrySubDivisionCode string ls_InvoiceBillAddrCity string ls_InvoiceBillAddrPostalCode string ls_InvoiceBillAddrId string ls_InvoiceBillAddrLine1 string ls_InvoiceMetaDataCreateTime string ls_InvoiceMetaDataLastUpdatedTime string ls_InvoiceId string ls_Time integer i integer li_Count_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. loo_JsonToken = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject") if li_rc < 0 then destroy loo_JsonToken MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_JsonToken.LoadFile("qa_data/tokens/qb-access-token.json") loo_Rest = create oleobject // Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0 li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest") // Connect to the REST server. li_BTls = 1 li_Port = 443 li_BAutoReconnect = 1 li_Success = loo_Rest.Connect("sandbox-quickbooks.api.intuit.com",li_Port,li_BTls,li_BAutoReconnect) loo_SbAuth = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbAuth.ConnectToNewObject("Chilkat.StringBuilder") loo_SbAuth.Append("Bearer ") loo_SbAuth.Append(loo_JsonToken.StringOf("access_token")) loo_Rest.Authorization = loo_SbAuth.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. // -------------------------------------------------------------------------- // 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 loo_JsonReq = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonReq.ConnectToNewObject("Chilkat.JsonObject") loo_JsonReq.UpdateString("DocNumber","1070") loo_JsonReq.UpdateString("SyncToken","0") loo_JsonReq.UpdateString("domain","QBO") loo_JsonReq.UpdateNumber("Balance","150.0") loo_JsonReq.UpdateString("BillAddr.City","Bayshore") loo_JsonReq.UpdateString("BillAddr.Line1","4581 Finch St.") loo_JsonReq.UpdateString("BillAddr.PostalCode","94326") loo_JsonReq.UpdateString("BillAddr.Lat","INVALID") loo_JsonReq.UpdateString("BillAddr.Long","INVALID") loo_JsonReq.UpdateString("BillAddr.CountrySubDivisionCode","CA") loo_JsonReq.UpdateString("BillAddr.Id","2") loo_JsonReq.UpdateString("TxnDate","2015-07-24") loo_JsonReq.UpdateNumber("TotalAmt","150.0") loo_JsonReq.UpdateString("CustomerRef.name","Amy's Bird Sanctuary") loo_JsonReq.UpdateString("CustomerRef.value","1") loo_JsonReq.UpdateString("CustomerMemo.value","Added customer memo.") loo_JsonReq.UpdateString("ShipAddr.City","Bayshore") loo_JsonReq.UpdateString("ShipAddr.Line1","4581 Finch St.") loo_JsonReq.UpdateString("ShipAddr.PostalCode","94326") loo_JsonReq.UpdateString("ShipAddr.Lat","INVALID") loo_JsonReq.UpdateString("ShipAddr.Long","INVALID") loo_JsonReq.UpdateString("ShipAddr.CountrySubDivisionCode","CA") loo_JsonReq.UpdateString("ShipAddr.Id","109") loo_JsonReq.UpdateNewArray("LinkedTxn") loo_JsonReq.UpdateString("DueDate","2015-08-23") loo_JsonReq.UpdateString("PrintStatus","NeedToPrint") loo_JsonReq.UpdateString("EmailStatus","NotSet") loo_JsonReq.UpdateBool("sparse",0) loo_JsonReq.UpdateInt("Line[0].LineNum",1) loo_JsonReq.UpdateNumber("Line[0].Amount","150.0") loo_JsonReq.UpdateString("Line[0].SalesItemLineDetail.TaxCodeRef.value","NON") loo_JsonReq.UpdateString("Line[0].SalesItemLineDetail.ItemRef.name","Services") loo_JsonReq.UpdateString("Line[0].SalesItemLineDetail.ItemRef.value","1") loo_JsonReq.UpdateString("Line[0].Id","1") loo_JsonReq.UpdateString("Line[0].DetailType","SalesItemLineDetail") loo_JsonReq.UpdateString("Line[1].DetailType","SubTotalLineDetail") loo_JsonReq.UpdateNumber("Line[1].Amount","150.0") loo_JsonReq.UpdateNewObject("Line[1].SubTotalLineDetail") loo_JsonReq.UpdateBool("ApplyTaxAfterDiscount",0) loo_JsonReq.UpdateString("CustomField[0].DefinitionId","1") loo_JsonReq.UpdateString("CustomField[0].Type","StringType") loo_JsonReq.UpdateString("CustomField[0].Name","Crew #") loo_JsonReq.UpdateString("Id","239") loo_JsonReq.UpdateInt("TxnTaxDetail.TotalTax",0) loo_JsonReq.UpdateString("MetaData.CreateTime","2015-07-24T10:35:08-07:00") loo_JsonReq.UpdateString("MetaData.LastUpdatedTime","2015-07-24T10:35:08-07:00") loo_SbRequestBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder") loo_JsonReq.EmitSb(loo_SbRequestBody) loo_Rest.AddHeader("Content-Type","application/json") loo_Rest.AddHeader("Accept","application/json") loo_Rest.AllowHeaderFolding = 0 loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") li_Success = loo_Rest.FullRequestSb("POST","/v3/company/<realmID>/invoice",loo_SbRequestBody,loo_SbResponseBody) if li_Success <> 1 then Write-Debug loo_Rest.LastErrorText destroy loo_JsonToken destroy loo_Rest destroy loo_SbAuth destroy loo_JsonReq destroy loo_SbRequestBody destroy loo_SbResponseBody return end if li_RespStatusCode = loo_Rest.ResponseStatusCode // Success is indicated by a 200 response status code. Write-Debug "response status code = " + string(li_RespStatusCode) loo_JsonResponse = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject") loo_JsonResponse.LoadSb(loo_SbResponseBody) loo_JsonResponse.EmitCompact = 0 Write-Debug loo_JsonResponse.Emit() if loo_Rest.ResponseStatusCode <> 200 then Write-Debug "Failed." destroy loo_JsonToken destroy loo_Rest destroy loo_SbAuth destroy loo_JsonReq destroy loo_SbRequestBody destroy loo_SbResponseBody destroy loo_JsonResponse return end if // 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" // } // ls_InvoiceTxnDate = loo_JsonResponse.StringOf("Invoice.TxnDate") ls_InvoiceDomain = loo_JsonResponse.StringOf("Invoice.domain") ls_InvoicePrintStatus = loo_JsonResponse.StringOf("Invoice.PrintStatus") ls_InvoiceTotalAmt = loo_JsonResponse.StringOf("Invoice.TotalAmt") ls_InvoiceDueDate = loo_JsonResponse.StringOf("Invoice.DueDate") li_InvoiceApplyTaxAfterDiscount = loo_JsonResponse.BoolOf("Invoice.ApplyTaxAfterDiscount") ls_InvoiceDocNumber = loo_JsonResponse.StringOf("Invoice.DocNumber") li_InvoiceSparse = loo_JsonResponse.BoolOf("Invoice.sparse") ls_InvoiceCustomerMemoValue = loo_JsonResponse.StringOf("Invoice.CustomerMemo.value") li_InvoiceDeposit = loo_JsonResponse.IntOf("Invoice.Deposit") ls_InvoiceBalance = loo_JsonResponse.StringOf("Invoice.Balance") ls_InvoiceCustomerRefName = loo_JsonResponse.StringOf("Invoice.CustomerRef.name") ls_InvoiceCustomerRefValue = loo_JsonResponse.StringOf("Invoice.CustomerRef.value") li_InvoiceTxnTaxDetailTotalTax = loo_JsonResponse.IntOf("Invoice.TxnTaxDetail.TotalTax") ls_InvoiceSyncToken = loo_JsonResponse.StringOf("Invoice.SyncToken") ls_InvoiceShipAddrCountrySubDivisionCode = loo_JsonResponse.StringOf("Invoice.ShipAddr.CountrySubDivisionCode") ls_InvoiceShipAddrCity = loo_JsonResponse.StringOf("Invoice.ShipAddr.City") ls_InvoiceShipAddrPostalCode = loo_JsonResponse.StringOf("Invoice.ShipAddr.PostalCode") ls_InvoiceShipAddrId = loo_JsonResponse.StringOf("Invoice.ShipAddr.Id") ls_InvoiceShipAddrLine1 = loo_JsonResponse.StringOf("Invoice.ShipAddr.Line1") ls_InvoiceEmailStatus = loo_JsonResponse.StringOf("Invoice.EmailStatus") ls_InvoiceBillAddrCountrySubDivisionCode = loo_JsonResponse.StringOf("Invoice.BillAddr.CountrySubDivisionCode") ls_InvoiceBillAddrCity = loo_JsonResponse.StringOf("Invoice.BillAddr.City") ls_InvoiceBillAddrPostalCode = loo_JsonResponse.StringOf("Invoice.BillAddr.PostalCode") ls_InvoiceBillAddrId = loo_JsonResponse.StringOf("Invoice.BillAddr.Id") ls_InvoiceBillAddrLine1 = loo_JsonResponse.StringOf("Invoice.BillAddr.Line1") ls_InvoiceMetaDataCreateTime = loo_JsonResponse.StringOf("Invoice.MetaData.CreateTime") ls_InvoiceMetaDataLastUpdatedTime = loo_JsonResponse.StringOf("Invoice.MetaData.LastUpdatedTime") ls_InvoiceId = loo_JsonResponse.StringOf("Invoice.Id") ls_Time = loo_JsonResponse.StringOf("time") i = 0 li_Count_i = loo_JsonResponse.SizeOfArray("Invoice.Line") do while i < li_Count_i loo_JsonResponse.I = i li_LineNum = loo_JsonResponse.IntOf("Invoice.Line[i].LineNum") ls_Amount = loo_JsonResponse.StringOf("Invoice.Line[i].Amount") ls_SalesItemLineDetailTaxCodeRefValue = loo_JsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value") ls_SalesItemLineDetailItemRefName = loo_JsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.name") ls_SalesItemLineDetailItemRefValue = loo_JsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.value") ls_Id = loo_JsonResponse.StringOf("Invoice.Line[i].Id") ls_DetailType = loo_JsonResponse.StringOf("Invoice.Line[i].DetailType") i = i + 1 loop i = 0 li_Count_i = loo_JsonResponse.SizeOfArray("Invoice.LinkedTxn") do while i < li_Count_i loo_JsonResponse.I = i i = i + 1 loop i = 0 li_Count_i = loo_JsonResponse.SizeOfArray("Invoice.CustomField") do while i < li_Count_i loo_JsonResponse.I = i ls_DefinitionId = loo_JsonResponse.StringOf("Invoice.CustomField[i].DefinitionId") ls_InvType = loo_JsonResponse.StringOf("Invoice.CustomField[i].Type") ls_Name = loo_JsonResponse.StringOf("Invoice.CustomField[i].Name") i = i + 1 loop destroy loo_JsonToken destroy loo_Rest destroy loo_SbAuth destroy loo_JsonReq destroy loo_SbRequestBody destroy loo_SbResponseBody destroy loo_JsonResponse |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.