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 Query an InvoiceDemonstrates how to query for invoices matching a SELECT statement via the Quickbooks REST API. For more information, see https://www.developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/invoice#query-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") 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 REST connection and setup of the AWS credentials ; can be done once. After connecting, any number of REST calls can be made. ; The "auto reconnect" property passed to rest.Connect indicates that if ; the connection is lost, a REST method call will automatically reconnect ; if needed. ; -------------------------------------------------------------------------- ; This is a GET request, so there should be no Content-Type ; This line of code is just to make sure.. $oRest.RemoveHeader("Content-Type") $oRest.AddHeader("Accept","application/json") $oRest.AllowHeaderFolding = False ; Add a SELECT statement $oRest.AddQueryParam("query","select * from Invoice where id = '239'") $oSbResponseBody = ObjCreate("Chilkat.StringBuilder") $bSuccess = $oRest.FullRequestNoBodySb("GET","/v3/company/<realmID>/invoice",$oSbResponseBody) If ($bSuccess <> True) Then ConsoleWrite($oRest.LastErrorText & @CRLF) Exit EndIf Local $iRespStatusCode = $oRest.ResponseStatusCode If ($iRespStatusCode >= 400) Then ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF) ConsoleWrite("Response Header:" & @CRLF) ConsoleWrite($oRest.ResponseHeader & @CRLF) ConsoleWrite("Response Body:" & @CRLF) ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF) Exit EndIf ; Success is indicated by a 200 response status. ConsoleWrite("response status code = " & $iRespStatusCode & @CRLF) $oJson = ObjCreate("Chilkat.JsonObject") $oJson.LoadSb($oSbResponseBody) $oJson.EmitCompact = False ConsoleWrite($oJson.Emit() & @CRLF) ; Sample output: ; Use the this online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON ; { ; "QueryResponse": { ; "startPosition": 1, ; "totalCount": 1, ; "maxResults": 1, ; "Invoice": [ ; { ; "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" ; }, ; "ShipAddr": { ; "City": "Bayshore", ; "Line1": "4581 Finch St.", ; "PostalCode": "94326", ; "Lat": "INVALID", ; "Long": "INVALID", ; "CountrySubDivisionCode": "CA", ; "Id": "109" ; }, ; "LinkedTxn": [], ; "DueDate": "2015-08-23", ; "PrintStatus": "NeedToPrint", ; "Deposit": 0, ; "sparse": false, ; "EmailStatus": "NotSet", ; "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" ; } ; } ; ] ; }, ; "time": "2015-07-24T10:38:50.01-07:00" ; } Local $sDocNumber Local $sSyncToken Local $sDomain Local $sBalance Local $sBillAddrCity Local $sBillAddrLine1 Local $sBillAddrPostalCode Local $sBillAddrLat Local $sBillAddrLong Local $sBillAddrCountrySubDivisionCode Local $sBillAddrId Local $sTxnDate Local $sTotalAmt Local $sCustomerRefName Local $sCustomerRefValue Local $sShipAddrCity Local $sShipAddrLine1 Local $sShipAddrPostalCode Local $sShipAddrLat Local $sShipAddrLong Local $sShipAddrCountrySubDivisionCode Local $sShipAddrId Local $sDueDate Local $sPrintStatus Local $iDeposit Local $bSparse Local $sEmailStatus Local $bApplyTaxAfterDiscount Local $sId Local $iTxnTaxDetailTotalTax Local $sMetaDataCreateTime Local $sMetaDataLastUpdatedTime Local $iJ Local $iCount_j Local $iLineNum Local $sAmount Local $sSalesItemLineDetailTaxCodeRefValue Local $sSalesItemLineDetailItemRefName Local $sSalesItemLineDetailItemRefValue Local $sDetailType Local $sDefinitionId Local $sInvType Local $sName Local $iQueryResponseStartPosition = $oJson.IntOf("QueryResponse.startPosition") Local $iQueryResponseTotalCount = $oJson.IntOf("QueryResponse.totalCount") Local $iQueryResponseMaxResults = $oJson.IntOf("QueryResponse.maxResults") Local $sTime = $oJson.StringOf("time") Local $i = 0 Local $iCount_i = $oJson.SizeOfArray("QueryResponse.Invoice") While $i < $iCount_i $oJson.I = $i $sDocNumber = $oJson.StringOf("QueryResponse.Invoice[i].DocNumber") $sSyncToken = $oJson.StringOf("QueryResponse.Invoice[i].SyncToken") $sDomain = $oJson.StringOf("QueryResponse.Invoice[i].domain") $sBalance = $oJson.StringOf("QueryResponse.Invoice[i].Balance") $sBillAddrCity = $oJson.StringOf("QueryResponse.Invoice[i].BillAddr.City") $sBillAddrLine1 = $oJson.StringOf("QueryResponse.Invoice[i].BillAddr.Line1") $sBillAddrPostalCode = $oJson.StringOf("QueryResponse.Invoice[i].BillAddr.PostalCode") $sBillAddrLat = $oJson.StringOf("QueryResponse.Invoice[i].BillAddr.Lat") $sBillAddrLong = $oJson.StringOf("QueryResponse.Invoice[i].BillAddr.Long") $sBillAddrCountrySubDivisionCode = $oJson.StringOf("QueryResponse.Invoice[i].BillAddr.CountrySubDivisionCode") $sBillAddrId = $oJson.StringOf("QueryResponse.Invoice[i].BillAddr.Id") $sTxnDate = $oJson.StringOf("QueryResponse.Invoice[i].TxnDate") $sTotalAmt = $oJson.StringOf("QueryResponse.Invoice[i].TotalAmt") $sCustomerRefName = $oJson.StringOf("QueryResponse.Invoice[i].CustomerRef.name") $sCustomerRefValue = $oJson.StringOf("QueryResponse.Invoice[i].CustomerRef.value") $sShipAddrCity = $oJson.StringOf("QueryResponse.Invoice[i].ShipAddr.City") $sShipAddrLine1 = $oJson.StringOf("QueryResponse.Invoice[i].ShipAddr.Line1") $sShipAddrPostalCode = $oJson.StringOf("QueryResponse.Invoice[i].ShipAddr.PostalCode") $sShipAddrLat = $oJson.StringOf("QueryResponse.Invoice[i].ShipAddr.Lat") $sShipAddrLong = $oJson.StringOf("QueryResponse.Invoice[i].ShipAddr.Long") $sShipAddrCountrySubDivisionCode = $oJson.StringOf("QueryResponse.Invoice[i].ShipAddr.CountrySubDivisionCode") $sShipAddrId = $oJson.StringOf("QueryResponse.Invoice[i].ShipAddr.Id") $sDueDate = $oJson.StringOf("QueryResponse.Invoice[i].DueDate") $sPrintStatus = $oJson.StringOf("QueryResponse.Invoice[i].PrintStatus") $iDeposit = $oJson.IntOf("QueryResponse.Invoice[i].Deposit") $bSparse = $oJson.BoolOf("QueryResponse.Invoice[i].sparse") $sEmailStatus = $oJson.StringOf("QueryResponse.Invoice[i].EmailStatus") $bApplyTaxAfterDiscount = $oJson.BoolOf("QueryResponse.Invoice[i].ApplyTaxAfterDiscount") $sId = $oJson.StringOf("QueryResponse.Invoice[i].Id") $iTxnTaxDetailTotalTax = $oJson.IntOf("QueryResponse.Invoice[i].TxnTaxDetail.TotalTax") $sMetaDataCreateTime = $oJson.StringOf("QueryResponse.Invoice[i].MetaData.CreateTime") $sMetaDataLastUpdatedTime = $oJson.StringOf("QueryResponse.Invoice[i].MetaData.LastUpdatedTime") $iJ = 0 $iCount_j = $oJson.SizeOfArray("QueryResponse.Invoice[i].LinkedTxn") While $iJ < $iCount_j $oJson.J = $iJ $iJ = $iJ + 1 Wend $iJ = 0 $iCount_j = $oJson.SizeOfArray("QueryResponse.Invoice[i].Line") While $iJ < $iCount_j $oJson.J = $iJ $iLineNum = $oJson.IntOf("QueryResponse.Invoice[i].Line[j].LineNum") $sAmount = $oJson.StringOf("QueryResponse.Invoice[i].Line[j].Amount") $sSalesItemLineDetailTaxCodeRefValue = $oJson.StringOf("QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.TaxCodeRef.value") $sSalesItemLineDetailItemRefName = $oJson.StringOf("QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.ItemRef.name") $sSalesItemLineDetailItemRefValue = $oJson.StringOf("QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.ItemRef.value") $sId = $oJson.StringOf("QueryResponse.Invoice[i].Line[j].Id") $sDetailType = $oJson.StringOf("QueryResponse.Invoice[i].Line[j].DetailType") $iJ = $iJ + 1 Wend $iJ = 0 $iCount_j = $oJson.SizeOfArray("QueryResponse.Invoice[i].CustomField") While $iJ < $iCount_j $oJson.J = $iJ $sDefinitionId = $oJson.StringOf("QueryResponse.Invoice[i].CustomField[j].DefinitionId") $sInvType = $oJson.StringOf("QueryResponse.Invoice[i].CustomField[j].Type") $sName = $oJson.StringOf("QueryResponse.Invoice[i].CustomField[j].Name") $iJ = $iJ + 1 Wend $i = $i + 1 Wend |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.