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 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
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 sInvoiceDocNumber String sInvoiceSyncToken String sInvoiceDomain String sInvoiceBalance String sInvoiceBillAddrCity String sInvoiceBillAddrLine1 String sInvoiceBillAddrPostalCode String sInvoiceBillAddrLat String sInvoiceBillAddrLong String sInvoiceBillAddrCountrySubDivisionCode String sInvoiceBillAddrId String sInvoiceTxnDate String sInvoiceTotalAmt String sInvoiceCustomerRefName String sInvoiceCustomerRefValue String sInvoiceShipAddrCity String sInvoiceShipAddrLine1 String sInvoiceShipAddrPostalCode String sInvoiceShipAddrLat String sInvoiceShipAddrLong String sInvoiceShipAddrCountrySubDivisionCode String sInvoiceShipAddrId String sInvoiceDueDate String sInvoicePrintStatus Integer iInvoiceDeposit Boolean iInvoiceSparse String sInvoiceEmailStatus Boolean iInvoiceApplyTaxAfterDiscount String sInvoiceId Integer iInvoiceTxnTaxDetailTotalTax String sInvoiceMetaDataCreateTime String sInvoiceMetaDataLastUpdatedTime 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: // { // "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 Get Create (RefClass(cComChilkatJsonObject)) To hoJsonReq If (Not(IsComObjectCreated(hoJsonReq))) Begin Send CreateComObject of hoJsonReq End Get ComUpdateString Of hoJsonReq "Line[0].DetailType" "SalesItemLineDetail" To iSuccess Get ComUpdateNumber Of hoJsonReq "Line[0].Amount" "100.0" 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 "CustomerRef.value" "1" 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": { // "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" // } // Get ComStringOf Of hoJsonResponse "Invoice.DocNumber" To sInvoiceDocNumber Get ComStringOf Of hoJsonResponse "Invoice.SyncToken" To sInvoiceSyncToken Get ComStringOf Of hoJsonResponse "Invoice.domain" To sInvoiceDomain Get ComStringOf Of hoJsonResponse "Invoice.Balance" To sInvoiceBalance Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.City" To sInvoiceBillAddrCity Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Line1" To sInvoiceBillAddrLine1 Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.PostalCode" To sInvoiceBillAddrPostalCode Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Lat" To sInvoiceBillAddrLat Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Long" To sInvoiceBillAddrLong Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.CountrySubDivisionCode" To sInvoiceBillAddrCountrySubDivisionCode Get ComStringOf Of hoJsonResponse "Invoice.BillAddr.Id" To sInvoiceBillAddrId Get ComStringOf Of hoJsonResponse "Invoice.TxnDate" To sInvoiceTxnDate Get ComStringOf Of hoJsonResponse "Invoice.TotalAmt" To sInvoiceTotalAmt Get ComStringOf Of hoJsonResponse "Invoice.CustomerRef.name" To sInvoiceCustomerRefName Get ComStringOf Of hoJsonResponse "Invoice.CustomerRef.value" To sInvoiceCustomerRefValue Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.City" To sInvoiceShipAddrCity Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Line1" To sInvoiceShipAddrLine1 Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.PostalCode" To sInvoiceShipAddrPostalCode Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Lat" To sInvoiceShipAddrLat Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Long" To sInvoiceShipAddrLong Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.CountrySubDivisionCode" To sInvoiceShipAddrCountrySubDivisionCode Get ComStringOf Of hoJsonResponse "Invoice.ShipAddr.Id" To sInvoiceShipAddrId Get ComStringOf Of hoJsonResponse "Invoice.DueDate" To sInvoiceDueDate Get ComStringOf Of hoJsonResponse "Invoice.PrintStatus" To sInvoicePrintStatus Get ComIntOf Of hoJsonResponse "Invoice.Deposit" To iInvoiceDeposit Get ComBoolOf Of hoJsonResponse "Invoice.sparse" To iInvoiceSparse Get ComStringOf Of hoJsonResponse "Invoice.EmailStatus" To sInvoiceEmailStatus Get ComBoolOf Of hoJsonResponse "Invoice.ApplyTaxAfterDiscount" To iInvoiceApplyTaxAfterDiscount Get ComStringOf Of hoJsonResponse "Invoice.Id" To sInvoiceId Get ComIntOf Of hoJsonResponse "Invoice.TxnTaxDetail.TotalTax" To iInvoiceTxnTaxDetailTotalTax Get ComStringOf Of hoJsonResponse "Invoice.MetaData.CreateTime" To sInvoiceMetaDataCreateTime Get ComStringOf Of hoJsonResponse "Invoice.MetaData.LastUpdatedTime" To sInvoiceMetaDataLastUpdatedTime Get ComStringOf Of hoJsonResponse "time" To sTime 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.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.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.