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
(AutoIt) 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
; 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. $oJsonToken = ObjCreate("Chilkat.JsonObject") Local $bSuccess = $oJsonToken.LoadFile("qa_data/tokens/qb-access-token.json") $oRest = ObjCreate("Chilkat.Rest") ; Connect to the REST server. Local $bTls = True Local $iPort = 443 Local $bAutoReconnect = True Local $bSuccess = $oRest.Connect("sandbox-quickbooks.api.intuit.com",$iPort,$bTls,$bAutoReconnect) $oSbAuth = ObjCreate("Chilkat.StringBuilder") $oSbAuth.Append("Bearer ") $oSbAuth.Append($oJsonToken.StringOf("access_token")) $oRest.Authorization = $oSbAuth.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 $oJsonReq = ObjCreate("Chilkat.JsonObject") $oJsonReq.UpdateString("DocNumber","1070") $oJsonReq.UpdateString("SyncToken","0") $oJsonReq.UpdateString("domain","QBO") $oJsonReq.UpdateNumber("Balance","150.0") $oJsonReq.UpdateString("BillAddr.City","Bayshore") $oJsonReq.UpdateString("BillAddr.Line1","4581 Finch St.") $oJsonReq.UpdateString("BillAddr.PostalCode","94326") $oJsonReq.UpdateString("BillAddr.Lat","INVALID") $oJsonReq.UpdateString("BillAddr.Long","INVALID") $oJsonReq.UpdateString("BillAddr.CountrySubDivisionCode","CA") $oJsonReq.UpdateString("BillAddr.Id","2") $oJsonReq.UpdateString("TxnDate","2015-07-24") $oJsonReq.UpdateNumber("TotalAmt","150.0") $oJsonReq.UpdateString("CustomerRef.name","Amy's Bird Sanctuary") $oJsonReq.UpdateString("CustomerRef.value","1") $oJsonReq.UpdateString("CustomerMemo.value","Added customer memo.") $oJsonReq.UpdateString("ShipAddr.City","Bayshore") $oJsonReq.UpdateString("ShipAddr.Line1","4581 Finch St.") $oJsonReq.UpdateString("ShipAddr.PostalCode","94326") $oJsonReq.UpdateString("ShipAddr.Lat","INVALID") $oJsonReq.UpdateString("ShipAddr.Long","INVALID") $oJsonReq.UpdateString("ShipAddr.CountrySubDivisionCode","CA") $oJsonReq.UpdateString("ShipAddr.Id","109") $oJsonReq.UpdateNewArray("LinkedTxn") $oJsonReq.UpdateString("DueDate","2015-08-23") $oJsonReq.UpdateString("PrintStatus","NeedToPrint") $oJsonReq.UpdateString("EmailStatus","NotSet") $oJsonReq.UpdateBool("sparse",False) $oJsonReq.UpdateInt("Line[0].LineNum",1) $oJsonReq.UpdateNumber("Line[0].Amount","150.0") $oJsonReq.UpdateString("Line[0].SalesItemLineDetail.TaxCodeRef.value","NON") $oJsonReq.UpdateString("Line[0].SalesItemLineDetail.ItemRef.name","Services") $oJsonReq.UpdateString("Line[0].SalesItemLineDetail.ItemRef.value","1") $oJsonReq.UpdateString("Line[0].Id","1") $oJsonReq.UpdateString("Line[0].DetailType","SalesItemLineDetail") $oJsonReq.UpdateString("Line[1].DetailType","SubTotalLineDetail") $oJsonReq.UpdateNumber("Line[1].Amount","150.0") $oJsonReq.UpdateNewObject("Line[1].SubTotalLineDetail") $oJsonReq.UpdateBool("ApplyTaxAfterDiscount",False) $oJsonReq.UpdateString("CustomField[0].DefinitionId","1") $oJsonReq.UpdateString("CustomField[0].Type","StringType") $oJsonReq.UpdateString("CustomField[0].Name","Crew #") $oJsonReq.UpdateString("Id","239") $oJsonReq.UpdateInt("TxnTaxDetail.TotalTax",0) $oJsonReq.UpdateString("MetaData.CreateTime","2015-07-24T10:35:08-07:00") $oJsonReq.UpdateString("MetaData.LastUpdatedTime","2015-07-24T10:35:08-07:00") $oSbRequestBody = ObjCreate("Chilkat.StringBuilder") $oJsonReq.EmitSb($oSbRequestBody) $oRest.AddHeader("Content-Type","application/json") $oRest.AddHeader("Accept","application/json") $oRest.AllowHeaderFolding = False $oSbResponseBody = ObjCreate("Chilkat.StringBuilder") $bSuccess = $oRest.FullRequestSb("POST","/v3/company/<realmID>/invoice",$oSbRequestBody,$oSbResponseBody) If ($bSuccess <> True) Then ConsoleWrite($oRest.LastErrorText & @CRLF) Exit EndIf Local $iRespStatusCode = $oRest.ResponseStatusCode ; Success is indicated by a 200 response status code. ConsoleWrite("response status code = " & $iRespStatusCode & @CRLF) $oJsonResponse = ObjCreate("Chilkat.JsonObject") $oJsonResponse.LoadSb($oSbResponseBody) $oJsonResponse.EmitCompact = False ConsoleWrite($oJsonResponse.Emit() & @CRLF) If ($oRest.ResponseStatusCode <> 200) Then ConsoleWrite("Failed." & @CRLF) Exit 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": "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" ; } ; Local $iLineNum Local $sAmount Local $sSalesItemLineDetailTaxCodeRefValue Local $sSalesItemLineDetailItemRefName Local $sSalesItemLineDetailItemRefValue Local $sId Local $sDetailType Local $sDefinitionId Local $sInvType Local $sName Local $sInvoiceTxnDate = $oJsonResponse.StringOf("Invoice.TxnDate") Local $sInvoiceDomain = $oJsonResponse.StringOf("Invoice.domain") Local $sInvoicePrintStatus = $oJsonResponse.StringOf("Invoice.PrintStatus") Local $sInvoiceTotalAmt = $oJsonResponse.StringOf("Invoice.TotalAmt") Local $sInvoiceDueDate = $oJsonResponse.StringOf("Invoice.DueDate") Local $bInvoiceApplyTaxAfterDiscount = $oJsonResponse.BoolOf("Invoice.ApplyTaxAfterDiscount") Local $sInvoiceDocNumber = $oJsonResponse.StringOf("Invoice.DocNumber") Local $bInvoiceSparse = $oJsonResponse.BoolOf("Invoice.sparse") Local $sInvoiceCustomerMemoValue = $oJsonResponse.StringOf("Invoice.CustomerMemo.value") Local $iInvoiceDeposit = $oJsonResponse.IntOf("Invoice.Deposit") Local $sInvoiceBalance = $oJsonResponse.StringOf("Invoice.Balance") Local $sInvoiceCustomerRefName = $oJsonResponse.StringOf("Invoice.CustomerRef.name") Local $sInvoiceCustomerRefValue = $oJsonResponse.StringOf("Invoice.CustomerRef.value") Local $iInvoiceTxnTaxDetailTotalTax = $oJsonResponse.IntOf("Invoice.TxnTaxDetail.TotalTax") Local $sInvoiceSyncToken = $oJsonResponse.StringOf("Invoice.SyncToken") Local $sInvoiceShipAddrCountrySubDivisionCode = $oJsonResponse.StringOf("Invoice.ShipAddr.CountrySubDivisionCode") Local $sInvoiceShipAddrCity = $oJsonResponse.StringOf("Invoice.ShipAddr.City") Local $sInvoiceShipAddrPostalCode = $oJsonResponse.StringOf("Invoice.ShipAddr.PostalCode") Local $sInvoiceShipAddrId = $oJsonResponse.StringOf("Invoice.ShipAddr.Id") Local $sInvoiceShipAddrLine1 = $oJsonResponse.StringOf("Invoice.ShipAddr.Line1") Local $sInvoiceEmailStatus = $oJsonResponse.StringOf("Invoice.EmailStatus") Local $sInvoiceBillAddrCountrySubDivisionCode = $oJsonResponse.StringOf("Invoice.BillAddr.CountrySubDivisionCode") Local $sInvoiceBillAddrCity = $oJsonResponse.StringOf("Invoice.BillAddr.City") Local $sInvoiceBillAddrPostalCode = $oJsonResponse.StringOf("Invoice.BillAddr.PostalCode") Local $sInvoiceBillAddrId = $oJsonResponse.StringOf("Invoice.BillAddr.Id") Local $sInvoiceBillAddrLine1 = $oJsonResponse.StringOf("Invoice.BillAddr.Line1") Local $sInvoiceMetaDataCreateTime = $oJsonResponse.StringOf("Invoice.MetaData.CreateTime") Local $sInvoiceMetaDataLastUpdatedTime = $oJsonResponse.StringOf("Invoice.MetaData.LastUpdatedTime") Local $sInvoiceId = $oJsonResponse.StringOf("Invoice.Id") Local $sTime = $oJsonResponse.StringOf("time") Local $i = 0 Local $iCount_i = $oJsonResponse.SizeOfArray("Invoice.Line") While $i < $iCount_i $oJsonResponse.I = $i $iLineNum = $oJsonResponse.IntOf("Invoice.Line[i].LineNum") $sAmount = $oJsonResponse.StringOf("Invoice.Line[i].Amount") $sSalesItemLineDetailTaxCodeRefValue = $oJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value") $sSalesItemLineDetailItemRefName = $oJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.name") $sSalesItemLineDetailItemRefValue = $oJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.value") $sId = $oJsonResponse.StringOf("Invoice.Line[i].Id") $sDetailType = $oJsonResponse.StringOf("Invoice.Line[i].DetailType") $i = $i + 1 Wend $i = 0 $iCount_i = $oJsonResponse.SizeOfArray("Invoice.LinkedTxn") While $i < $iCount_i $oJsonResponse.I = $i $i = $i + 1 Wend $i = 0 $iCount_i = $oJsonResponse.SizeOfArray("Invoice.CustomField") While $i < $iCount_i $oJsonResponse.I = $i $sDefinitionId = $oJsonResponse.StringOf("Invoice.CustomField[i].DefinitionId") $sInvType = $oJsonResponse.StringOf("Invoice.CustomField[i].Type") $sName = $oJsonResponse.StringOf("Invoice.CustomField[i].Name") $i = $i + 1 Wend |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.