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

Chilkat2-Python 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

 

 

 

(Chilkat2-Python) 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

Chilkat2 Python Downloads

install with pip

pip3 install chilkat2

or download... Python Module for Windows, Linux, Alpine Linux, MacOS, Solaris

import sys
import chilkat2

# 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.
jsonToken = chilkat2.JsonObject()
success = jsonToken.LoadFile("qa_data/tokens/qb-access-token.json")

rest = chilkat2.Rest()

# Connect to the REST server.
bTls = True
port = 443
bAutoReconnect = True
success = rest.Connect("sandbox-quickbooks.api.intuit.com",port,bTls,bAutoReconnect)

sbAuth = chilkat2.StringBuilder()
sbAuth.Append("Bearer ")
sbAuth.Append(jsonToken.StringOf("access_token"))
rest.Authorization = sbAuth.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???)
rest.AddHeader("Content-Type","application/octet-stream")
rest.AllowHeaderFolding = False

sbResponseBody = chilkat2.StringBuilder()
success = rest.FullRequestNoBodySb("POST","/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>",sbResponseBody)
if (success != True):
    print(rest.LastErrorText)
    sys.exit()

respStatusCode = rest.ResponseStatusCode

# Success is indicated by a 200 response status code.
print("response status code = " + str(respStatusCode))

jsonResponse = chilkat2.JsonObject()
jsonResponse.LoadSb(sbResponseBody)
jsonResponse.EmitCompact = False
print(jsonResponse.Emit())

if (rest.ResponseStatusCode != 200):
    print("Failed.")
    sys.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"
# }
# 

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

i = 0
count_i = jsonResponse.SizeOfArray("Invoice.TxnTaxDetail.TaxLine")
while i < count_i :
    jsonResponse.I = i
    DetailType = jsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].DetailType")
    Amount = jsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].Amount")
    TaxLineDetailNetAmountTaxable = jsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable")
    TaxLineDetailTaxPercent = jsonResponse.IntOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent")
    TaxLineDetailTaxRateRefValue = jsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value")
    TaxLineDetailPercentBased = jsonResponse.BoolOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased")
    i = i + 1

i = 0
count_i = jsonResponse.SizeOfArray("Invoice.CustomField")
while i < count_i :
    jsonResponse.I = i
    StringValue = jsonResponse.StringOf("Invoice.CustomField[i].StringValue")
    Type = jsonResponse.StringOf("Invoice.CustomField[i].Type")
    Name = jsonResponse.StringOf("Invoice.CustomField[i].Name")
    i = i + 1


 

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