Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

AutoIt Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(AutoIt) Quickbooks Send an Invoice

Demonstrates how to send 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#send-an-invoice

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

; 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.
; --------------------------------------------------------------------------

; Technically, the POST has an empty request body, but the Quickbooks documentation indicates that 
; the Content-Type header should be set to "application/octet-stream", which really makes no sense
; because there is not content. (How can no content have a type???)
$oRest.AddHeader("Content-Type","application/octet-stream")
$oRest.AllowHeaderFolding = False

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oRest.FullRequestNoBodySb("POST","/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>",$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": "2013-03-14",
;     "domain": "QBO",
;     "CurrencyRef": {
;       "name": "United States Dollar",
;       "value": "USD"
;     },
;     "ShipDate": "2013-03-01",
;     "TrackingNum": "123456789",
;     "ClassRef": {
;       "name": "Class 1",
;       "value": "200900000000000003901"
;     },
;     "PrintStatus": "NeedToPrint",
;     "SalesTermRef": {
;       "value": "4"
;     },
;     "DeliveryInfo": {
;       "DeliveryType": "Email",
;       "DeliveryTime": "2014-12-17T11:50:52-08:00"
;     },
;     "TotalAmt": 52.0,
;     "Line": [
;       {
;         "Description": "Sample invoice create request",
;         "DetailType": "SalesItemLineDetail",
;         "SalesItemLineDetail": {
;           "TaxCodeRef": {
;             "value": "TAX"
;           },
;           "Qty": 1,
;           "UnitPrice": 50,
;           "ServiceDate": "2013-03-04",
;           "ItemRef": {
;             "name": "Hours",
;             "value": "2"
;           }
;         },
;         "LineNum": 1,
;         "Amount": 50.0,
;         "Id": "1"
;       },
;       {
;         "DetailType": "SubTotalLineDetail",
;         "Amount": 50.0,
;         "SubTotalLineDetail": {}
;       },
;       {
;         "DetailType": "DiscountLineDetail",
;         "Amount": 5.0,
;         "DiscountLineDetail": {
;           "DiscountAccountRef": {
;             "name": "Discounts given",
;             "value": "30"
;           },
;           "PercentBased": true,
;           "DiscountPercent": 10
;         }
;       },
;       {
;         "DetailType": "SalesItemLineDetail",
;         "Amount": 2.0,
;         "SalesItemLineDetail": {
;           "ItemRef": {
;             "value": "SHIPPING_ITEM_ID"
;           }
;         }
;       }
;     ],
;     "DueDate": "2013-05-13",
;     "MetaData": {
;       "CreateTime": "2013-03-14T01:42:16-07:00",
;       "LastUpdatedTime": "2014-12-17T11:50:58-08:00"
;     },
;     "DocNumber": "Sample_Inv#2",
;     "PrivateNote": "Summary for sample invoice",
;     "sparse": false,
;     "DepositToAccountRef": {
;       "name": "Undeposited Funds",
;       "value": "4"
;     },
;     "CustomerMemo": {
;       "value": "This is the customer message"
;     },
;     "EmailStatus": "EmailSent",
;     "Deposit": 12.0,
;     "Balance": 40.0,
;     "CustomerRef": {
;       "name": "Mr V3 Service Customer Jr2",
;       "value": "15"
;     },
;     "TxnTaxDetail": {
;       "TxnTaxCodeRef": {
;         "value": "5"
;       },
;       "TotalTax": 5.0,
;       "TaxLine": [
;         {
;           "DetailType": "TaxLineDetail",
;           "Amount": 5.0,
;           "TaxLineDetail": {
;             "NetAmountTaxable": 50.0,
;             "TaxPercent": 10,
;             "TaxRateRef": {
;               "value": "2"
;             },
;             "PercentBased": true
;           }
;         }
;       ]
;     },
;     "SyncToken": "0",
;     "BillEmail": {
;       "Address": "test@intuit.com"
;     },
;     "ShipAddr": {
;       "City": "San Jose",
;       "Country": "USA",
;       "Line5": "Cube 999",
;       "Line4": "Dept 12",
;       "Line3": "123 street",
;       "Line2": "Building 1",
;       "Line1": "Intuit",
;       "PostalCode": "95123",
;       "Lat": "37.2374847",
;       "Long": "-121.8277925",
;       "CountrySubDivisionCode": "CA",
;       "Id": "36"
;     },
;     "DepartmentRef": {
;       "name": "Mountain View",
;       "value": "1"
;     },
;     "ShipMethodRef": {
;       "name": "UPS",
;       "value": "UPS"
;     },
;     "BillAddr": {
;       "City": "Mountain View",
;       "Country": "USA",
;       "Line5": "Cube 999",
;       "Line4": "Dept 12",
;       "Line3": "123 street",
;       "Line2": "Building 1",
;       "Line1": "Google",
;       "PostalCode": "95123",
;       "Lat": "37.2374847",
;       "Long": "-121.8277925",
;       "CountrySubDivisionCode": "CA",
;       "Id": "35"
;     },
;     "ApplyTaxAfterDiscount": false,
;     "CustomField": [
;       {
;         "StringValue": "Custom1",
;         "Type": "StringType",
;         "Name": "Custom 1"
;       },
;       {
;         "StringValue": "Custom2",
;         "Type": "StringType",
;         "Name": "Custom 2"
;       },
;       {
;         "StringValue": "Custom3",
;         "Type": "StringType",
;         "Name": "Custom 3"
;       }
;     ],
;     "Id": "96"
;   },
;   "time": "2013-03-14T13:32:04.895-07:00"
; }
; 

Local $sDescription
Local $sDetailType
Local $sSalesItemLineDetailTaxCodeRefValue
Local $iSalesItemLineDetailQty
Local $iSalesItemLineDetailUnitPrice
Local $sSalesItemLineDetailServiceDate
Local $sSalesItemLineDetailItemRefName
Local $sSalesItemLineDetailItemRefValue
Local $iLineNum
Local $sAmount
Local $sId
Local $sDiscountLineDetailDiscountAccountRefName
Local $sDiscountLineDetailDiscountAccountRefValue
Local $bDiscountLineDetailPercentBased
Local $iDiscountLineDetailDiscountPercent
Local $sTaxLineDetailNetAmountTaxable
Local $iTaxLineDetailTaxPercent
Local $sTaxLineDetailTaxRateRefValue
Local $bTaxLineDetailPercentBased
Local $sStringValue
Local $sType
Local $sName

Local $sInvoiceTxnDate = $oJsonResponse.StringOf("Invoice.TxnDate")
Local $sInvoiceDomain = $oJsonResponse.StringOf("Invoice.domain")
Local $sInvoiceCurrencyRefName = $oJsonResponse.StringOf("Invoice.CurrencyRef.name")
Local $sInvoiceCurrencyRefValue = $oJsonResponse.StringOf("Invoice.CurrencyRef.value")
Local $sInvoiceShipDate = $oJsonResponse.StringOf("Invoice.ShipDate")
Local $sInvoiceTrackingNum = $oJsonResponse.StringOf("Invoice.TrackingNum")
Local $sInvoiceClassRefName = $oJsonResponse.StringOf("Invoice.ClassRef.name")
Local $sInvoiceClassRefValue = $oJsonResponse.StringOf("Invoice.ClassRef.value")
Local $sInvoicePrintStatus = $oJsonResponse.StringOf("Invoice.PrintStatus")
Local $sInvoiceSalesTermRefValue = $oJsonResponse.StringOf("Invoice.SalesTermRef.value")
Local $sInvoiceDeliveryInfoDeliveryType = $oJsonResponse.StringOf("Invoice.DeliveryInfo.DeliveryType")
Local $sInvoiceDeliveryInfoDeliveryTime = $oJsonResponse.StringOf("Invoice.DeliveryInfo.DeliveryTime")
Local $sInvoiceTotalAmt = $oJsonResponse.StringOf("Invoice.TotalAmt")
Local $sInvoiceDueDate = $oJsonResponse.StringOf("Invoice.DueDate")
Local $sInvoiceMetaDataCreateTime = $oJsonResponse.StringOf("Invoice.MetaData.CreateTime")
Local $sInvoiceMetaDataLastUpdatedTime = $oJsonResponse.StringOf("Invoice.MetaData.LastUpdatedTime")
Local $sInvoiceDocNumber = $oJsonResponse.StringOf("Invoice.DocNumber")
Local $sInvoicePrivateNote = $oJsonResponse.StringOf("Invoice.PrivateNote")
Local $bInvoiceSparse = $oJsonResponse.BoolOf("Invoice.sparse")
Local $sInvoiceDepositToAccountRefName = $oJsonResponse.StringOf("Invoice.DepositToAccountRef.name")
Local $sInvoiceDepositToAccountRefValue = $oJsonResponse.StringOf("Invoice.DepositToAccountRef.value")
Local $sInvoiceCustomerMemoValue = $oJsonResponse.StringOf("Invoice.CustomerMemo.value")
Local $sInvoiceEmailStatus = $oJsonResponse.StringOf("Invoice.EmailStatus")
Local $sInvoiceDeposit = $oJsonResponse.StringOf("Invoice.Deposit")
Local $sInvoiceBalance = $oJsonResponse.StringOf("Invoice.Balance")
Local $sInvoiceCustomerRefName = $oJsonResponse.StringOf("Invoice.CustomerRef.name")
Local $sInvoiceCustomerRefValue = $oJsonResponse.StringOf("Invoice.CustomerRef.value")
Local $sInvoiceTxnTaxDetailTxnTaxCodeRefValue = $oJsonResponse.StringOf("Invoice.TxnTaxDetail.TxnTaxCodeRef.value")
Local $sInvoiceTxnTaxDetailTotalTax = $oJsonResponse.StringOf("Invoice.TxnTaxDetail.TotalTax")
Local $sInvoiceSyncToken = $oJsonResponse.StringOf("Invoice.SyncToken")
Local $sInvoiceBillEmailAddress = $oJsonResponse.StringOf("Invoice.BillEmail.Address")
Local $sInvoiceShipAddrCity = $oJsonResponse.StringOf("Invoice.ShipAddr.City")
Local $sInvoiceShipAddrCountry = $oJsonResponse.StringOf("Invoice.ShipAddr.Country")
Local $sInvoiceShipAddrLine5 = $oJsonResponse.StringOf("Invoice.ShipAddr.Line5")
Local $sInvoiceShipAddrLine4 = $oJsonResponse.StringOf("Invoice.ShipAddr.Line4")
Local $sInvoiceShipAddrLine3 = $oJsonResponse.StringOf("Invoice.ShipAddr.Line3")
Local $sInvoiceShipAddrLine2 = $oJsonResponse.StringOf("Invoice.ShipAddr.Line2")
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 $sInvoiceDepartmentRefName = $oJsonResponse.StringOf("Invoice.DepartmentRef.name")
Local $sInvoiceDepartmentRefValue = $oJsonResponse.StringOf("Invoice.DepartmentRef.value")
Local $sInvoiceShipMethodRefName = $oJsonResponse.StringOf("Invoice.ShipMethodRef.name")
Local $sInvoiceShipMethodRefValue = $oJsonResponse.StringOf("Invoice.ShipMethodRef.value")
Local $sInvoiceBillAddrCity = $oJsonResponse.StringOf("Invoice.BillAddr.City")
Local $sInvoiceBillAddrCountry = $oJsonResponse.StringOf("Invoice.BillAddr.Country")
Local $sInvoiceBillAddrLine5 = $oJsonResponse.StringOf("Invoice.BillAddr.Line5")
Local $sInvoiceBillAddrLine4 = $oJsonResponse.StringOf("Invoice.BillAddr.Line4")
Local $sInvoiceBillAddrLine3 = $oJsonResponse.StringOf("Invoice.BillAddr.Line3")
Local $sInvoiceBillAddrLine2 = $oJsonResponse.StringOf("Invoice.BillAddr.Line2")
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 $bInvoiceApplyTaxAfterDiscount = $oJsonResponse.BoolOf("Invoice.ApplyTaxAfterDiscount")
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
    $sDescription = $oJsonResponse.StringOf("Invoice.Line[i].Description")
    $sDetailType = $oJsonResponse.StringOf("Invoice.Line[i].DetailType")
    $sSalesItemLineDetailTaxCodeRefValue = $oJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value")
    $iSalesItemLineDetailQty = $oJsonResponse.IntOf("Invoice.Line[i].SalesItemLineDetail.Qty")
    $iSalesItemLineDetailUnitPrice = $oJsonResponse.IntOf("Invoice.Line[i].SalesItemLineDetail.UnitPrice")
    $sSalesItemLineDetailServiceDate = $oJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ServiceDate")
    $sSalesItemLineDetailItemRefName = $oJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.name")
    $sSalesItemLineDetailItemRefValue = $oJsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.value")
    $iLineNum = $oJsonResponse.IntOf("Invoice.Line[i].LineNum")
    $sAmount = $oJsonResponse.StringOf("Invoice.Line[i].Amount")
    $sId = $oJsonResponse.StringOf("Invoice.Line[i].Id")
    $sDiscountLineDetailDiscountAccountRefName = $oJsonResponse.StringOf("Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.name")
    $sDiscountLineDetailDiscountAccountRefValue = $oJsonResponse.StringOf("Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.value")
    $bDiscountLineDetailPercentBased = $oJsonResponse.BoolOf("Invoice.Line[i].DiscountLineDetail.PercentBased")
    $iDiscountLineDetailDiscountPercent = $oJsonResponse.IntOf("Invoice.Line[i].DiscountLineDetail.DiscountPercent")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJsonResponse.SizeOfArray("Invoice.TxnTaxDetail.TaxLine")
While $i < $iCount_i
    $oJsonResponse.I = $i
    $sDetailType = $oJsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].DetailType")
    $sAmount = $oJsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].Amount")
    $sTaxLineDetailNetAmountTaxable = $oJsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable")
    $iTaxLineDetailTaxPercent = $oJsonResponse.IntOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent")
    $sTaxLineDetailTaxRateRefValue = $oJsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value")
    $bTaxLineDetailPercentBased = $oJsonResponse.BoolOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJsonResponse.SizeOfArray("Invoice.CustomField")
While $i < $iCount_i
    $oJsonResponse.I = $i
    $sStringValue = $oJsonResponse.StringOf("Invoice.CustomField[i].StringValue")
    $sType = $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.