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
Jira
Lightspeed
MYOB
Magento
Mailgun

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
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
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 Query an Invoice

Demonstrates 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

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]

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 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..
CkRest_RemoveHeader $rest "Content-Type"

CkRest_AddHeader $rest "Accept" "application/json"
CkRest_put_AllowHeaderFolding $rest 0

# Add a SELECT statement 
CkRest_AddQueryParam $rest "query" "select * from Invoice where id = '239'"

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/v3/company/<realmID>/invoice" $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]
if {$respStatusCode >= 400} then {
    puts "Response Status Code = $respStatusCode"
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkJsonObject $jsonToken
    delete_CkRest $rest
    delete_CkStringBuilder $sbAuth
    delete_CkStringBuilder $sbResponseBody
    exit
}

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

set json [new_CkJsonObject]

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

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

set QueryResponseStartPosition [CkJsonObject_IntOf $json "QueryResponse.startPosition"]
set QueryResponseTotalCount [CkJsonObject_IntOf $json "QueryResponse.totalCount"]
set QueryResponseMaxResults [CkJsonObject_IntOf $json "QueryResponse.maxResults"]
set time [CkJsonObject_stringOf $json "time"]
set i 0
set count_i [CkJsonObject_SizeOfArray $json "QueryResponse.Invoice"]
while {$i < $count_i} {
    CkJsonObject_put_I $json $i
    set DocNumber [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].DocNumber"]
    set SyncToken [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].SyncToken"]
    set domain [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].domain"]
    set Balance [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].Balance"]
    set BillAddrCity [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].BillAddr.City"]
    set BillAddrLine1 [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].BillAddr.Line1"]
    set BillAddrPostalCode [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].BillAddr.PostalCode"]
    set BillAddrLat [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].BillAddr.Lat"]
    set BillAddrLong [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].BillAddr.Long"]
    set BillAddrCountrySubDivisionCode [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].BillAddr.CountrySubDivisionCode"]
    set BillAddrId [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].BillAddr.Id"]
    set TxnDate [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].TxnDate"]
    set TotalAmt [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].TotalAmt"]
    set CustomerRefName [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].CustomerRef.name"]
    set CustomerRefValue [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].CustomerRef.value"]
    set ShipAddrCity [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].ShipAddr.City"]
    set ShipAddrLine1 [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].ShipAddr.Line1"]
    set ShipAddrPostalCode [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].ShipAddr.PostalCode"]
    set ShipAddrLat [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].ShipAddr.Lat"]
    set ShipAddrLong [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].ShipAddr.Long"]
    set ShipAddrCountrySubDivisionCode [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].ShipAddr.CountrySubDivisionCode"]
    set ShipAddrId [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].ShipAddr.Id"]
    set DueDate [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].DueDate"]
    set PrintStatus [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].PrintStatus"]
    set Deposit [CkJsonObject_IntOf $json "QueryResponse.Invoice[i].Deposit"]
    set sparse [CkJsonObject_BoolOf $json "QueryResponse.Invoice[i].sparse"]
    set EmailStatus [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].EmailStatus"]
    set ApplyTaxAfterDiscount [CkJsonObject_BoolOf $json "QueryResponse.Invoice[i].ApplyTaxAfterDiscount"]
    set Id [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].Id"]
    set TxnTaxDetailTotalTax [CkJsonObject_IntOf $json "QueryResponse.Invoice[i].TxnTaxDetail.TotalTax"]
    set MetaDataCreateTime [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].MetaData.CreateTime"]
    set MetaDataLastUpdatedTime [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].MetaData.LastUpdatedTime"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "QueryResponse.Invoice[i].LinkedTxn"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "QueryResponse.Invoice[i].Line"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        set LineNum [CkJsonObject_IntOf $json "QueryResponse.Invoice[i].Line[j].LineNum"]
        set Amount [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].Line[j].Amount"]
        set SalesItemLineDetailTaxCodeRefValue [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.TaxCodeRef.value"]
        set SalesItemLineDetailItemRefName [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.ItemRef.name"]
        set SalesItemLineDetailItemRefValue [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.ItemRef.value"]
        set Id [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].Line[j].Id"]
        set DetailType [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].Line[j].DetailType"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "QueryResponse.Invoice[i].CustomField"]
    while {$j < $count_j} {
        CkJsonObject_put_J $json $j
        set DefinitionId [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].CustomField[j].DefinitionId"]
        set invType [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].CustomField[j].Type"]
        set Name [CkJsonObject_stringOf $json "QueryResponse.Invoice[i].CustomField[j].Name"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

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

 

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