PowerBuilder
PowerBuilder
Quickbooks Send an Invoice
See more QuickBooks Examples
Demonstrates how to send an invoice using the Quickbooks REST API.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_JsonToken
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbAuth
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
string ls_Description
string ls_DetailType
string ls_SalesItemLineDetailTaxCodeRefValue
integer li_SalesItemLineDetailQty
integer li_SalesItemLineDetailUnitPrice
string ls_SalesItemLineDetailServiceDate
string ls_SalesItemLineDetailItemRefName
string ls_SalesItemLineDetailItemRefValue
integer li_LineNum
string ls_Amount
string ls_Id
string ls_DiscountLineDetailDiscountAccountRefName
string ls_DiscountLineDetailDiscountAccountRefValue
integer li_DiscountLineDetailPercentBased
integer li_DiscountLineDetailDiscountPercent
string ls_TaxLineDetailNetAmountTaxable
integer li_TaxLineDetailTaxPercent
string ls_TaxLineDetailTaxRateRefValue
integer li_TaxLineDetailPercentBased
string ls_StringValue
string ls_Type
string ls_Name
string ls_InvoiceTxnDate
string ls_InvoiceDomain
string ls_InvoiceCurrencyRefName
string ls_InvoiceCurrencyRefValue
string ls_InvoiceShipDate
string ls_InvoiceTrackingNum
string ls_InvoiceClassRefName
string ls_InvoiceClassRefValue
string ls_InvoicePrintStatus
string ls_InvoiceSalesTermRefValue
string ls_InvoiceDeliveryInfoDeliveryType
string ls_InvoiceDeliveryInfoDeliveryTime
string ls_InvoiceTotalAmt
string ls_InvoiceDueDate
string ls_InvoiceMetaDataCreateTime
string ls_InvoiceMetaDataLastUpdatedTime
string ls_InvoiceDocNumber
string ls_InvoicePrivateNote
integer li_InvoiceSparse
string ls_InvoiceDepositToAccountRefName
string ls_InvoiceDepositToAccountRefValue
string ls_InvoiceCustomerMemoValue
string ls_InvoiceEmailStatus
string ls_InvoiceDeposit
string ls_InvoiceBalance
string ls_InvoiceCustomerRefName
string ls_InvoiceCustomerRefValue
string ls_InvoiceTxnTaxDetailTxnTaxCodeRefValue
string ls_InvoiceTxnTaxDetailTotalTax
string ls_InvoiceSyncToken
string ls_InvoiceBillEmailAddress
string ls_InvoiceShipAddrCity
string ls_InvoiceShipAddrCountry
string ls_InvoiceShipAddrLine5
string ls_InvoiceShipAddrLine4
string ls_InvoiceShipAddrLine3
string ls_InvoiceShipAddrLine2
string ls_InvoiceShipAddrLine1
string ls_InvoiceShipAddrPostalCode
string ls_InvoiceShipAddrLat
string ls_InvoiceShipAddrLong
string ls_InvoiceShipAddrCountrySubDivisionCode
string ls_InvoiceShipAddrId
string ls_InvoiceDepartmentRefName
string ls_InvoiceDepartmentRefValue
string ls_InvoiceShipMethodRefName
string ls_InvoiceShipMethodRefValue
string ls_InvoiceBillAddrCity
string ls_InvoiceBillAddrCountry
string ls_InvoiceBillAddrLine5
string ls_InvoiceBillAddrLine4
string ls_InvoiceBillAddrLine3
string ls_InvoiceBillAddrLine2
string ls_InvoiceBillAddrLine1
string ls_InvoiceBillAddrPostalCode
string ls_InvoiceBillAddrLat
string ls_InvoiceBillAddrLong
string ls_InvoiceBillAddrCountrySubDivisionCode
string ls_InvoiceBillAddrId
integer li_InvoiceApplyTaxAfterDiscount
string ls_InvoiceId
string ls_Time
integer i
integer li_Count_i
li_Success = 0
// 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.
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
destroy loo_JsonToken
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_JsonToken.LoadFile("qa_data/tokens/qb-access-token.json")
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
// Connect to the REST server.
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("sandbox-quickbooks.api.intuit.com",li_Port,li_BTls,li_BAutoReconnect)
loo_SbAuth = create oleobject
li_rc = loo_SbAuth.ConnectToNewObject("Chilkat.StringBuilder")
loo_SbAuth.Append("Bearer ")
loo_SbAuth.Append(loo_JsonToken.StringOf("access_token"))
loo_Rest.Authorization = loo_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???)
loo_Rest.AddHeader("Content-Type","application/octet-stream")
loo_Rest.AllowHeaderFolding = 0
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Rest.FullRequestNoBodySb("POST","/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>",loo_SbResponseBody)
if li_Success <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_JsonToken
destroy loo_Rest
destroy loo_SbAuth
destroy loo_SbResponseBody
return
end if
li_RespStatusCode = loo_Rest.ResponseStatusCode
// Success is indicated by a 200 response status code.
Write-Debug "response status code = " + string(li_RespStatusCode)
loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject")
loo_JsonResponse.LoadSb(loo_SbResponseBody)
loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.Emit()
if loo_Rest.ResponseStatusCode <> 200 then
Write-Debug "Failed."
destroy loo_JsonToken
destroy loo_Rest
destroy loo_SbAuth
destroy loo_SbResponseBody
destroy loo_JsonResponse
return
end if
// 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"
// }
//
ls_InvoiceTxnDate = loo_JsonResponse.StringOf("Invoice.TxnDate")
ls_InvoiceDomain = loo_JsonResponse.StringOf("Invoice.domain")
ls_InvoiceCurrencyRefName = loo_JsonResponse.StringOf("Invoice.CurrencyRef.name")
ls_InvoiceCurrencyRefValue = loo_JsonResponse.StringOf("Invoice.CurrencyRef.value")
ls_InvoiceShipDate = loo_JsonResponse.StringOf("Invoice.ShipDate")
ls_InvoiceTrackingNum = loo_JsonResponse.StringOf("Invoice.TrackingNum")
ls_InvoiceClassRefName = loo_JsonResponse.StringOf("Invoice.ClassRef.name")
ls_InvoiceClassRefValue = loo_JsonResponse.StringOf("Invoice.ClassRef.value")
ls_InvoicePrintStatus = loo_JsonResponse.StringOf("Invoice.PrintStatus")
ls_InvoiceSalesTermRefValue = loo_JsonResponse.StringOf("Invoice.SalesTermRef.value")
ls_InvoiceDeliveryInfoDeliveryType = loo_JsonResponse.StringOf("Invoice.DeliveryInfo.DeliveryType")
ls_InvoiceDeliveryInfoDeliveryTime = loo_JsonResponse.StringOf("Invoice.DeliveryInfo.DeliveryTime")
ls_InvoiceTotalAmt = loo_JsonResponse.StringOf("Invoice.TotalAmt")
ls_InvoiceDueDate = loo_JsonResponse.StringOf("Invoice.DueDate")
ls_InvoiceMetaDataCreateTime = loo_JsonResponse.StringOf("Invoice.MetaData.CreateTime")
ls_InvoiceMetaDataLastUpdatedTime = loo_JsonResponse.StringOf("Invoice.MetaData.LastUpdatedTime")
ls_InvoiceDocNumber = loo_JsonResponse.StringOf("Invoice.DocNumber")
ls_InvoicePrivateNote = loo_JsonResponse.StringOf("Invoice.PrivateNote")
li_InvoiceSparse = loo_JsonResponse.BoolOf("Invoice.sparse")
ls_InvoiceDepositToAccountRefName = loo_JsonResponse.StringOf("Invoice.DepositToAccountRef.name")
ls_InvoiceDepositToAccountRefValue = loo_JsonResponse.StringOf("Invoice.DepositToAccountRef.value")
ls_InvoiceCustomerMemoValue = loo_JsonResponse.StringOf("Invoice.CustomerMemo.value")
ls_InvoiceEmailStatus = loo_JsonResponse.StringOf("Invoice.EmailStatus")
ls_InvoiceDeposit = loo_JsonResponse.StringOf("Invoice.Deposit")
ls_InvoiceBalance = loo_JsonResponse.StringOf("Invoice.Balance")
ls_InvoiceCustomerRefName = loo_JsonResponse.StringOf("Invoice.CustomerRef.name")
ls_InvoiceCustomerRefValue = loo_JsonResponse.StringOf("Invoice.CustomerRef.value")
ls_InvoiceTxnTaxDetailTxnTaxCodeRefValue = loo_JsonResponse.StringOf("Invoice.TxnTaxDetail.TxnTaxCodeRef.value")
ls_InvoiceTxnTaxDetailTotalTax = loo_JsonResponse.StringOf("Invoice.TxnTaxDetail.TotalTax")
ls_InvoiceSyncToken = loo_JsonResponse.StringOf("Invoice.SyncToken")
ls_InvoiceBillEmailAddress = loo_JsonResponse.StringOf("Invoice.BillEmail.Address")
ls_InvoiceShipAddrCity = loo_JsonResponse.StringOf("Invoice.ShipAddr.City")
ls_InvoiceShipAddrCountry = loo_JsonResponse.StringOf("Invoice.ShipAddr.Country")
ls_InvoiceShipAddrLine5 = loo_JsonResponse.StringOf("Invoice.ShipAddr.Line5")
ls_InvoiceShipAddrLine4 = loo_JsonResponse.StringOf("Invoice.ShipAddr.Line4")
ls_InvoiceShipAddrLine3 = loo_JsonResponse.StringOf("Invoice.ShipAddr.Line3")
ls_InvoiceShipAddrLine2 = loo_JsonResponse.StringOf("Invoice.ShipAddr.Line2")
ls_InvoiceShipAddrLine1 = loo_JsonResponse.StringOf("Invoice.ShipAddr.Line1")
ls_InvoiceShipAddrPostalCode = loo_JsonResponse.StringOf("Invoice.ShipAddr.PostalCode")
ls_InvoiceShipAddrLat = loo_JsonResponse.StringOf("Invoice.ShipAddr.Lat")
ls_InvoiceShipAddrLong = loo_JsonResponse.StringOf("Invoice.ShipAddr.Long")
ls_InvoiceShipAddrCountrySubDivisionCode = loo_JsonResponse.StringOf("Invoice.ShipAddr.CountrySubDivisionCode")
ls_InvoiceShipAddrId = loo_JsonResponse.StringOf("Invoice.ShipAddr.Id")
ls_InvoiceDepartmentRefName = loo_JsonResponse.StringOf("Invoice.DepartmentRef.name")
ls_InvoiceDepartmentRefValue = loo_JsonResponse.StringOf("Invoice.DepartmentRef.value")
ls_InvoiceShipMethodRefName = loo_JsonResponse.StringOf("Invoice.ShipMethodRef.name")
ls_InvoiceShipMethodRefValue = loo_JsonResponse.StringOf("Invoice.ShipMethodRef.value")
ls_InvoiceBillAddrCity = loo_JsonResponse.StringOf("Invoice.BillAddr.City")
ls_InvoiceBillAddrCountry = loo_JsonResponse.StringOf("Invoice.BillAddr.Country")
ls_InvoiceBillAddrLine5 = loo_JsonResponse.StringOf("Invoice.BillAddr.Line5")
ls_InvoiceBillAddrLine4 = loo_JsonResponse.StringOf("Invoice.BillAddr.Line4")
ls_InvoiceBillAddrLine3 = loo_JsonResponse.StringOf("Invoice.BillAddr.Line3")
ls_InvoiceBillAddrLine2 = loo_JsonResponse.StringOf("Invoice.BillAddr.Line2")
ls_InvoiceBillAddrLine1 = loo_JsonResponse.StringOf("Invoice.BillAddr.Line1")
ls_InvoiceBillAddrPostalCode = loo_JsonResponse.StringOf("Invoice.BillAddr.PostalCode")
ls_InvoiceBillAddrLat = loo_JsonResponse.StringOf("Invoice.BillAddr.Lat")
ls_InvoiceBillAddrLong = loo_JsonResponse.StringOf("Invoice.BillAddr.Long")
ls_InvoiceBillAddrCountrySubDivisionCode = loo_JsonResponse.StringOf("Invoice.BillAddr.CountrySubDivisionCode")
ls_InvoiceBillAddrId = loo_JsonResponse.StringOf("Invoice.BillAddr.Id")
li_InvoiceApplyTaxAfterDiscount = loo_JsonResponse.BoolOf("Invoice.ApplyTaxAfterDiscount")
ls_InvoiceId = loo_JsonResponse.StringOf("Invoice.Id")
ls_Time = loo_JsonResponse.StringOf("time")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("Invoice.Line")
do while i < li_Count_i
loo_JsonResponse.I = i
ls_Description = loo_JsonResponse.StringOf("Invoice.Line[i].Description")
ls_DetailType = loo_JsonResponse.StringOf("Invoice.Line[i].DetailType")
ls_SalesItemLineDetailTaxCodeRefValue = loo_JsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value")
li_SalesItemLineDetailQty = loo_JsonResponse.IntOf("Invoice.Line[i].SalesItemLineDetail.Qty")
li_SalesItemLineDetailUnitPrice = loo_JsonResponse.IntOf("Invoice.Line[i].SalesItemLineDetail.UnitPrice")
ls_SalesItemLineDetailServiceDate = loo_JsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ServiceDate")
ls_SalesItemLineDetailItemRefName = loo_JsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.name")
ls_SalesItemLineDetailItemRefValue = loo_JsonResponse.StringOf("Invoice.Line[i].SalesItemLineDetail.ItemRef.value")
li_LineNum = loo_JsonResponse.IntOf("Invoice.Line[i].LineNum")
ls_Amount = loo_JsonResponse.StringOf("Invoice.Line[i].Amount")
ls_Id = loo_JsonResponse.StringOf("Invoice.Line[i].Id")
ls_DiscountLineDetailDiscountAccountRefName = loo_JsonResponse.StringOf("Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.name")
ls_DiscountLineDetailDiscountAccountRefValue = loo_JsonResponse.StringOf("Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.value")
li_DiscountLineDetailPercentBased = loo_JsonResponse.BoolOf("Invoice.Line[i].DiscountLineDetail.PercentBased")
li_DiscountLineDetailDiscountPercent = loo_JsonResponse.IntOf("Invoice.Line[i].DiscountLineDetail.DiscountPercent")
i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("Invoice.TxnTaxDetail.TaxLine")
do while i < li_Count_i
loo_JsonResponse.I = i
ls_DetailType = loo_JsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].DetailType")
ls_Amount = loo_JsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].Amount")
ls_TaxLineDetailNetAmountTaxable = loo_JsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable")
li_TaxLineDetailTaxPercent = loo_JsonResponse.IntOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent")
ls_TaxLineDetailTaxRateRefValue = loo_JsonResponse.StringOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value")
li_TaxLineDetailPercentBased = loo_JsonResponse.BoolOf("Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased")
i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("Invoice.CustomField")
do while i < li_Count_i
loo_JsonResponse.I = i
ls_StringValue = loo_JsonResponse.StringOf("Invoice.CustomField[i].StringValue")
ls_Type = loo_JsonResponse.StringOf("Invoice.CustomField[i].Type")
ls_Name = loo_JsonResponse.StringOf("Invoice.CustomField[i].Name")
i = i + 1
loop
destroy loo_JsonToken
destroy loo_Rest
destroy loo_SbAuth
destroy loo_SbResponseBody
destroy loo_JsonResponse