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

Tcl 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

 

 

 

(Tcl) 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 Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

# 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.
set jsonToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/qb-access-token.json"]

set rest [new_CkRest]

# Connect to the REST server.
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "sandbox-quickbooks.api.intuit.com" $port $bTls $bAutoReconnect]

set sbAuth [new_CkStringBuilder]

CkStringBuilder_Append $sbAuth "Bearer "
CkStringBuilder_Append $sbAuth [CkJsonObject_stringOf $jsonToken "access_token"]
CkRest_put_Authorization $rest [CkStringBuilder_getAsString $sbAuth]

# --------------------------------------------------------------------------
# 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???)
CkRest_AddHeader $rest "Content-Type" "application/octet-stream"
CkRest_put_AllowHeaderFolding $rest 0

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "POST" "/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>" $sbResponseBody]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkJsonObject $jsonToken
    delete_CkRest $rest
    delete_CkStringBuilder $sbAuth
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]

# Success is indicated by a 200 response status code.
puts "response status code = $respStatusCode"

set jsonResponse [new_CkJsonObject]

CkJsonObject_LoadSb $jsonResponse $sbResponseBody
CkJsonObject_put_EmitCompact $jsonResponse 0
puts [CkJsonObject_emit $jsonResponse]

if {[CkRest_get_ResponseStatusCode $rest] != 200} then {
    puts "Failed."
    delete_CkJsonObject $jsonToken
    delete_CkRest $rest
    delete_CkStringBuilder $sbAuth
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jsonResponse
    exit
}

# 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"
# }
# 

set InvoiceTxnDate [CkJsonObject_stringOf $jsonResponse "Invoice.TxnDate"]
set InvoiceDomain [CkJsonObject_stringOf $jsonResponse "Invoice.domain"]
set InvoiceCurrencyRefName [CkJsonObject_stringOf $jsonResponse "Invoice.CurrencyRef.name"]
set InvoiceCurrencyRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.CurrencyRef.value"]
set InvoiceShipDate [CkJsonObject_stringOf $jsonResponse "Invoice.ShipDate"]
set InvoiceTrackingNum [CkJsonObject_stringOf $jsonResponse "Invoice.TrackingNum"]
set InvoiceClassRefName [CkJsonObject_stringOf $jsonResponse "Invoice.ClassRef.name"]
set InvoiceClassRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.ClassRef.value"]
set InvoicePrintStatus [CkJsonObject_stringOf $jsonResponse "Invoice.PrintStatus"]
set InvoiceSalesTermRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.SalesTermRef.value"]
set InvoiceDeliveryInfoDeliveryType [CkJsonObject_stringOf $jsonResponse "Invoice.DeliveryInfo.DeliveryType"]
set InvoiceDeliveryInfoDeliveryTime [CkJsonObject_stringOf $jsonResponse "Invoice.DeliveryInfo.DeliveryTime"]
set InvoiceTotalAmt [CkJsonObject_stringOf $jsonResponse "Invoice.TotalAmt"]
set InvoiceDueDate [CkJsonObject_stringOf $jsonResponse "Invoice.DueDate"]
set InvoiceMetaDataCreateTime [CkJsonObject_stringOf $jsonResponse "Invoice.MetaData.CreateTime"]
set InvoiceMetaDataLastUpdatedTime [CkJsonObject_stringOf $jsonResponse "Invoice.MetaData.LastUpdatedTime"]
set InvoiceDocNumber [CkJsonObject_stringOf $jsonResponse "Invoice.DocNumber"]
set InvoicePrivateNote [CkJsonObject_stringOf $jsonResponse "Invoice.PrivateNote"]
set InvoiceSparse [CkJsonObject_BoolOf $jsonResponse "Invoice.sparse"]
set InvoiceDepositToAccountRefName [CkJsonObject_stringOf $jsonResponse "Invoice.DepositToAccountRef.name"]
set InvoiceDepositToAccountRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.DepositToAccountRef.value"]
set InvoiceCustomerMemoValue [CkJsonObject_stringOf $jsonResponse "Invoice.CustomerMemo.value"]
set InvoiceEmailStatus [CkJsonObject_stringOf $jsonResponse "Invoice.EmailStatus"]
set InvoiceDeposit [CkJsonObject_stringOf $jsonResponse "Invoice.Deposit"]
set InvoiceBalance [CkJsonObject_stringOf $jsonResponse "Invoice.Balance"]
set InvoiceCustomerRefName [CkJsonObject_stringOf $jsonResponse "Invoice.CustomerRef.name"]
set InvoiceCustomerRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.CustomerRef.value"]
set InvoiceTxnTaxDetailTxnTaxCodeRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.TxnTaxDetail.TxnTaxCodeRef.value"]
set InvoiceTxnTaxDetailTotalTax [CkJsonObject_stringOf $jsonResponse "Invoice.TxnTaxDetail.TotalTax"]
set InvoiceSyncToken [CkJsonObject_stringOf $jsonResponse "Invoice.SyncToken"]
set InvoiceBillEmailAddress [CkJsonObject_stringOf $jsonResponse "Invoice.BillEmail.Address"]
set InvoiceShipAddrCity [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.City"]
set InvoiceShipAddrCountry [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Country"]
set InvoiceShipAddrLine5 [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Line5"]
set InvoiceShipAddrLine4 [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Line4"]
set InvoiceShipAddrLine3 [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Line3"]
set InvoiceShipAddrLine2 [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Line2"]
set InvoiceShipAddrLine1 [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Line1"]
set InvoiceShipAddrPostalCode [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.PostalCode"]
set InvoiceShipAddrLat [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Lat"]
set InvoiceShipAddrLong [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Long"]
set InvoiceShipAddrCountrySubDivisionCode [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.CountrySubDivisionCode"]
set InvoiceShipAddrId [CkJsonObject_stringOf $jsonResponse "Invoice.ShipAddr.Id"]
set InvoiceDepartmentRefName [CkJsonObject_stringOf $jsonResponse "Invoice.DepartmentRef.name"]
set InvoiceDepartmentRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.DepartmentRef.value"]
set InvoiceShipMethodRefName [CkJsonObject_stringOf $jsonResponse "Invoice.ShipMethodRef.name"]
set InvoiceShipMethodRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.ShipMethodRef.value"]
set InvoiceBillAddrCity [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.City"]
set InvoiceBillAddrCountry [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Country"]
set InvoiceBillAddrLine5 [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Line5"]
set InvoiceBillAddrLine4 [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Line4"]
set InvoiceBillAddrLine3 [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Line3"]
set InvoiceBillAddrLine2 [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Line2"]
set InvoiceBillAddrLine1 [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Line1"]
set InvoiceBillAddrPostalCode [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.PostalCode"]
set InvoiceBillAddrLat [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Lat"]
set InvoiceBillAddrLong [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Long"]
set InvoiceBillAddrCountrySubDivisionCode [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.CountrySubDivisionCode"]
set InvoiceBillAddrId [CkJsonObject_stringOf $jsonResponse "Invoice.BillAddr.Id"]
set InvoiceApplyTaxAfterDiscount [CkJsonObject_BoolOf $jsonResponse "Invoice.ApplyTaxAfterDiscount"]
set InvoiceId [CkJsonObject_stringOf $jsonResponse "Invoice.Id"]
set time [CkJsonObject_stringOf $jsonResponse "time"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "Invoice.Line"]
while {$i < $count_i} {
    CkJsonObject_put_I $jsonResponse $i
    set Description [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].Description"]
    set DetailType [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].DetailType"]
    set SalesItemLineDetailTaxCodeRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value"]
    set SalesItemLineDetailQty [CkJsonObject_IntOf $jsonResponse "Invoice.Line[i].SalesItemLineDetail.Qty"]
    set SalesItemLineDetailUnitPrice [CkJsonObject_IntOf $jsonResponse "Invoice.Line[i].SalesItemLineDetail.UnitPrice"]
    set SalesItemLineDetailServiceDate [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].SalesItemLineDetail.ServiceDate"]
    set SalesItemLineDetailItemRefName [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].SalesItemLineDetail.ItemRef.name"]
    set SalesItemLineDetailItemRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].SalesItemLineDetail.ItemRef.value"]
    set LineNum [CkJsonObject_IntOf $jsonResponse "Invoice.Line[i].LineNum"]
    set Amount [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].Amount"]
    set Id [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].Id"]
    set DiscountLineDetailDiscountAccountRefName [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.name"]
    set DiscountLineDetailDiscountAccountRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.value"]
    set DiscountLineDetailPercentBased [CkJsonObject_BoolOf $jsonResponse "Invoice.Line[i].DiscountLineDetail.PercentBased"]
    set DiscountLineDetailDiscountPercent [CkJsonObject_IntOf $jsonResponse "Invoice.Line[i].DiscountLineDetail.DiscountPercent"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "Invoice.TxnTaxDetail.TaxLine"]
while {$i < $count_i} {
    CkJsonObject_put_I $jsonResponse $i
    set DetailType [CkJsonObject_stringOf $jsonResponse "Invoice.TxnTaxDetail.TaxLine[i].DetailType"]
    set Amount [CkJsonObject_stringOf $jsonResponse "Invoice.TxnTaxDetail.TaxLine[i].Amount"]
    set TaxLineDetailNetAmountTaxable [CkJsonObject_stringOf $jsonResponse "Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable"]
    set TaxLineDetailTaxPercent [CkJsonObject_IntOf $jsonResponse "Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent"]
    set TaxLineDetailTaxRateRefValue [CkJsonObject_stringOf $jsonResponse "Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value"]
    set TaxLineDetailPercentBased [CkJsonObject_BoolOf $jsonResponse "Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "Invoice.CustomField"]
while {$i < $count_i} {
    CkJsonObject_put_I $jsonResponse $i
    set StringValue [CkJsonObject_stringOf $jsonResponse "Invoice.CustomField[i].StringValue"]
    set Type [CkJsonObject_stringOf $jsonResponse "Invoice.CustomField[i].Type"]
    set Name [CkJsonObject_stringOf $jsonResponse "Invoice.CustomField[i].Name"]
    set i [expr $i + 1]
}

delete_CkJsonObject $jsonToken
delete_CkRest $rest
delete_CkStringBuilder $sbAuth
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jsonResponse

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.