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 Create an InvoiceDemonstrates how to create an invoice via the Quickbooks REST API. For more information, see https://www.developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/invoice#create-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: ; { ; "Line": [ ; { ; "DetailType": "SalesItemLineDetail", ; "Amount": 100.0, ; "SalesItemLineDetail": { ; "ItemRef": { ; "name": "Services", ; "value": "1" ; } ; } ; } ; ], ; "CustomerRef": { ; "value": "1" ; } ; } ; ; Use the this online tool to generate the code from sample JSON: ; Generate Code to Create JSON $oJsonReq = ObjCreate("Chilkat.JsonObject") $oJsonReq.UpdateString("Line[0].DetailType","SalesItemLineDetail") $oJsonReq.UpdateNumber("Line[0].Amount","100.0") $oJsonReq.UpdateString("Line[0].SalesItemLineDetail.ItemRef.name","Services") $oJsonReq.UpdateString("Line[0].SalesItemLineDetail.ItemRef.value","1") $oJsonReq.UpdateString("CustomerRef.value","1") $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": { ; "DocNumber": "1069", ; "SyncToken": "0", ; "domain": "QBO", ; "Balance": 100.0, ; "BillAddr": { ; "City": "Bayshore", ; "Line1": "4581 Finch St.", ; "PostalCode": "94326", ; "Lat": "INVALID", ; "Long": "INVALID", ; "CountrySubDivisionCode": "CA", ; "Id": "2" ; }, ; "TxnDate": "2015-07-24", ; "TotalAmt": 100.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": 100.0, ; "SalesItemLineDetail": { ; "TaxCodeRef": { ; "value": "NON" ; }, ; "ItemRef": { ; "name": "Services", ; "value": "1" ; } ; }, ; "Id": "1", ; "DetailType": "SalesItemLineDetail" ; }, ; { ; "DetailType": "SubTotalLineDetail", ; "Amount": 100.0, ; "SubTotalLineDetail": {} ; } ; ], ; "ApplyTaxAfterDiscount": false, ; "CustomField": [ ; { ; "DefinitionId": "1", ; "Type": "StringType", ; "Name": "Crew #" ; } ; ], ; "Id": "238", ; "TxnTaxDetail": { ; "TotalTax": 0 ; }, ; "MetaData": { ; "CreateTime": "2015-07-24T10:33:39-07:00", ; "LastUpdatedTime": "2015-07-24T10:33:39-07:00" ; } ; }, ; "time": "2015-07-24T10:33:39.11-07:00" ; } ; Local $iLineNum Local $sAmount Local $sSalesItemLineDetailTaxCodeRefValue Local $sSalesItemLineDetailItemRefName Local $sSalesItemLineDetailItemRefValue Local $sId Local $sDetailType Local $sDefinitionId Local $sInvType Local $sName Local $sInvoiceDocNumber = $oJsonResponse.StringOf("Invoice.DocNumber") Local $sInvoiceSyncToken = $oJsonResponse.StringOf("Invoice.SyncToken") Local $sInvoiceDomain = $oJsonResponse.StringOf("Invoice.domain") Local $sInvoiceBalance = $oJsonResponse.StringOf("Invoice.Balance") Local $sInvoiceBillAddrCity = $oJsonResponse.StringOf("Invoice.BillAddr.City") Local $sInvoiceBillAddrLine1 = $oJsonResponse.StringOf("Invoice.BillAddr.Line1") Local $sInvoiceBillAddrPostalCode = $oJsonResponse.StringOf("Invoice.BillAddr.PostalCode") Local $sInvoiceBillAddrLat = $oJsonResponse.StringOf("Invoice.BillAddr.Lat") Local $sInvoiceBillAddrLong = $oJsonResponse.StringOf("Invoice.BillAddr.Long") Local $sInvoiceBillAddrCountrySubDivisionCode = $oJsonResponse.StringOf("Invoice.BillAddr.CountrySubDivisionCode") Local $sInvoiceBillAddrId = $oJsonResponse.StringOf("Invoice.BillAddr.Id") Local $sInvoiceTxnDate = $oJsonResponse.StringOf("Invoice.TxnDate") Local $sInvoiceTotalAmt = $oJsonResponse.StringOf("Invoice.TotalAmt") Local $sInvoiceCustomerRefName = $oJsonResponse.StringOf("Invoice.CustomerRef.name") Local $sInvoiceCustomerRefValue = $oJsonResponse.StringOf("Invoice.CustomerRef.value") Local $sInvoiceShipAddrCity = $oJsonResponse.StringOf("Invoice.ShipAddr.City") Local $sInvoiceShipAddrLine1 = $oJsonResponse.StringOf("Invoice.ShipAddr.Line1") Local $sInvoiceShipAddrPostalCode = $oJsonResponse.StringOf("Invoice.ShipAddr.PostalCode") Local $sInvoiceShipAddrLat = $oJsonResponse.StringOf("Invoice.ShipAddr.Lat") Local $sInvoiceShipAddrLong = $oJsonResponse.StringOf("Invoice.ShipAddr.Long") Local $sInvoiceShipAddrCountrySubDivisionCode = $oJsonResponse.StringOf("Invoice.ShipAddr.CountrySubDivisionCode") Local $sInvoiceShipAddrId = $oJsonResponse.StringOf("Invoice.ShipAddr.Id") Local $sInvoiceDueDate = $oJsonResponse.StringOf("Invoice.DueDate") Local $sInvoicePrintStatus = $oJsonResponse.StringOf("Invoice.PrintStatus") Local $iInvoiceDeposit = $oJsonResponse.IntOf("Invoice.Deposit") Local $bInvoiceSparse = $oJsonResponse.BoolOf("Invoice.sparse") Local $sInvoiceEmailStatus = $oJsonResponse.StringOf("Invoice.EmailStatus") Local $bInvoiceApplyTaxAfterDiscount = $oJsonResponse.BoolOf("Invoice.ApplyTaxAfterDiscount") Local $sInvoiceId = $oJsonResponse.StringOf("Invoice.Id") Local $iInvoiceTxnTaxDetailTotalTax = $oJsonResponse.IntOf("Invoice.TxnTaxDetail.TotalTax") Local $sInvoiceMetaDataCreateTime = $oJsonResponse.StringOf("Invoice.MetaData.CreateTime") Local $sInvoiceMetaDataLastUpdatedTime = $oJsonResponse.StringOf("Invoice.MetaData.LastUpdatedTime") Local $sTime = $oJsonResponse.StringOf("time") Local $i = 0 Local $iCount_i = $oJsonResponse.SizeOfArray("Invoice.LinkedTxn") While $i < $iCount_i $oJsonResponse.I = $i $i = $i + 1 Wend $i = 0 $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.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.