SQL Server
SQL Server
Quickbooks Send an Invoice
See more QuickBooks Examples
Demonstrates how to send an invoice using the Quickbooks REST API.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @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.
DECLARE @jsonToken int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/qb-access-token.json'
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT
-- Connect to the REST server.
DECLARE @bTls int
SELECT @bTls = 1
DECLARE @port int
SELECT @port = 443
DECLARE @bAutoReconnect int
SELECT @bAutoReconnect = 1
EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'sandbox-quickbooks.api.intuit.com', @port, @bTls, @bAutoReconnect
DECLARE @sbAuth int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbAuth OUT
EXEC sp_OAMethod @sbAuth, 'Append', @success OUT, 'Bearer '
EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'access_token'
EXEC sp_OAMethod @sbAuth, 'Append', @success OUT, @sTmp0
EXEC sp_OAMethod @sbAuth, 'GetAsString', @sTmp0 OUT
EXEC sp_OASetProperty @rest, 'Authorization', @sTmp0
-- --------------------------------------------------------------------------
-- 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???)
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/octet-stream'
EXEC sp_OASetProperty @rest, 'AllowHeaderFolding', 0
DECLARE @sbResponseBody int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'POST', '/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>', @sbResponseBody
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @sbAuth
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT
-- Success is indicated by a 200 response status code.
PRINT 'response status code = ' + @respStatusCode
DECLARE @jsonResponse int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonResponse OUT
EXEC sp_OAMethod @jsonResponse, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jsonResponse, 'EmitCompact', 0
EXEC sp_OAMethod @jsonResponse, 'Emit', @sTmp0 OUT
PRINT @sTmp0
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
IF @iTmp0 <> 200
BEGIN
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @sbAuth
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jsonResponse
RETURN
END
-- 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"
-- }
--
DECLARE @Description nvarchar(4000)
DECLARE @DetailType nvarchar(4000)
DECLARE @SalesItemLineDetailTaxCodeRefValue nvarchar(4000)
DECLARE @SalesItemLineDetailQty int
DECLARE @SalesItemLineDetailUnitPrice int
DECLARE @SalesItemLineDetailServiceDate nvarchar(4000)
DECLARE @SalesItemLineDetailItemRefName nvarchar(4000)
DECLARE @SalesItemLineDetailItemRefValue nvarchar(4000)
DECLARE @LineNum int
DECLARE @Amount nvarchar(4000)
DECLARE @Id nvarchar(4000)
DECLARE @DiscountLineDetailDiscountAccountRefName nvarchar(4000)
DECLARE @DiscountLineDetailDiscountAccountRefValue nvarchar(4000)
DECLARE @DiscountLineDetailPercentBased int
DECLARE @DiscountLineDetailDiscountPercent int
DECLARE @TaxLineDetailNetAmountTaxable nvarchar(4000)
DECLARE @TaxLineDetailTaxPercent int
DECLARE @TaxLineDetailTaxRateRefValue nvarchar(4000)
DECLARE @TaxLineDetailPercentBased int
DECLARE @StringValue nvarchar(4000)
DECLARE @Type nvarchar(4000)
DECLARE @Name nvarchar(4000)
DECLARE @InvoiceTxnDate nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceTxnDate OUT, 'Invoice.TxnDate'
DECLARE @InvoiceDomain nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDomain OUT, 'Invoice.domain'
DECLARE @InvoiceCurrencyRefName nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceCurrencyRefName OUT, 'Invoice.CurrencyRef.name'
DECLARE @InvoiceCurrencyRefValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceCurrencyRefValue OUT, 'Invoice.CurrencyRef.value'
DECLARE @InvoiceShipDate nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipDate OUT, 'Invoice.ShipDate'
DECLARE @InvoiceTrackingNum nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceTrackingNum OUT, 'Invoice.TrackingNum'
DECLARE @InvoiceClassRefName nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceClassRefName OUT, 'Invoice.ClassRef.name'
DECLARE @InvoiceClassRefValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceClassRefValue OUT, 'Invoice.ClassRef.value'
DECLARE @InvoicePrintStatus nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoicePrintStatus OUT, 'Invoice.PrintStatus'
DECLARE @InvoiceSalesTermRefValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceSalesTermRefValue OUT, 'Invoice.SalesTermRef.value'
DECLARE @InvoiceDeliveryInfoDeliveryType nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDeliveryInfoDeliveryType OUT, 'Invoice.DeliveryInfo.DeliveryType'
DECLARE @InvoiceDeliveryInfoDeliveryTime nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDeliveryInfoDeliveryTime OUT, 'Invoice.DeliveryInfo.DeliveryTime'
DECLARE @InvoiceTotalAmt nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceTotalAmt OUT, 'Invoice.TotalAmt'
DECLARE @InvoiceDueDate nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDueDate OUT, 'Invoice.DueDate'
DECLARE @InvoiceMetaDataCreateTime nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceMetaDataCreateTime OUT, 'Invoice.MetaData.CreateTime'
DECLARE @InvoiceMetaDataLastUpdatedTime nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceMetaDataLastUpdatedTime OUT, 'Invoice.MetaData.LastUpdatedTime'
DECLARE @InvoiceDocNumber nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDocNumber OUT, 'Invoice.DocNumber'
DECLARE @InvoicePrivateNote nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoicePrivateNote OUT, 'Invoice.PrivateNote'
DECLARE @InvoiceSparse int
EXEC sp_OAMethod @jsonResponse, 'BoolOf', @InvoiceSparse OUT, 'Invoice.sparse'
DECLARE @InvoiceDepositToAccountRefName nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDepositToAccountRefName OUT, 'Invoice.DepositToAccountRef.name'
DECLARE @InvoiceDepositToAccountRefValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDepositToAccountRefValue OUT, 'Invoice.DepositToAccountRef.value'
DECLARE @InvoiceCustomerMemoValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceCustomerMemoValue OUT, 'Invoice.CustomerMemo.value'
DECLARE @InvoiceEmailStatus nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceEmailStatus OUT, 'Invoice.EmailStatus'
DECLARE @InvoiceDeposit nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDeposit OUT, 'Invoice.Deposit'
DECLARE @InvoiceBalance nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBalance OUT, 'Invoice.Balance'
DECLARE @InvoiceCustomerRefName nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceCustomerRefName OUT, 'Invoice.CustomerRef.name'
DECLARE @InvoiceCustomerRefValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceCustomerRefValue OUT, 'Invoice.CustomerRef.value'
DECLARE @InvoiceTxnTaxDetailTxnTaxCodeRefValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceTxnTaxDetailTxnTaxCodeRefValue OUT, 'Invoice.TxnTaxDetail.TxnTaxCodeRef.value'
DECLARE @InvoiceTxnTaxDetailTotalTax nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceTxnTaxDetailTotalTax OUT, 'Invoice.TxnTaxDetail.TotalTax'
DECLARE @InvoiceSyncToken nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceSyncToken OUT, 'Invoice.SyncToken'
DECLARE @InvoiceBillEmailAddress nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillEmailAddress OUT, 'Invoice.BillEmail.Address'
DECLARE @InvoiceShipAddrCity nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrCity OUT, 'Invoice.ShipAddr.City'
DECLARE @InvoiceShipAddrCountry nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrCountry OUT, 'Invoice.ShipAddr.Country'
DECLARE @InvoiceShipAddrLine5 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrLine5 OUT, 'Invoice.ShipAddr.Line5'
DECLARE @InvoiceShipAddrLine4 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrLine4 OUT, 'Invoice.ShipAddr.Line4'
DECLARE @InvoiceShipAddrLine3 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrLine3 OUT, 'Invoice.ShipAddr.Line3'
DECLARE @InvoiceShipAddrLine2 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrLine2 OUT, 'Invoice.ShipAddr.Line2'
DECLARE @InvoiceShipAddrLine1 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrLine1 OUT, 'Invoice.ShipAddr.Line1'
DECLARE @InvoiceShipAddrPostalCode nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrPostalCode OUT, 'Invoice.ShipAddr.PostalCode'
DECLARE @InvoiceShipAddrLat nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrLat OUT, 'Invoice.ShipAddr.Lat'
DECLARE @InvoiceShipAddrLong nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrLong OUT, 'Invoice.ShipAddr.Long'
DECLARE @InvoiceShipAddrCountrySubDivisionCode nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrCountrySubDivisionCode OUT, 'Invoice.ShipAddr.CountrySubDivisionCode'
DECLARE @InvoiceShipAddrId nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipAddrId OUT, 'Invoice.ShipAddr.Id'
DECLARE @InvoiceDepartmentRefName nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDepartmentRefName OUT, 'Invoice.DepartmentRef.name'
DECLARE @InvoiceDepartmentRefValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceDepartmentRefValue OUT, 'Invoice.DepartmentRef.value'
DECLARE @InvoiceShipMethodRefName nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipMethodRefName OUT, 'Invoice.ShipMethodRef.name'
DECLARE @InvoiceShipMethodRefValue nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceShipMethodRefValue OUT, 'Invoice.ShipMethodRef.value'
DECLARE @InvoiceBillAddrCity nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrCity OUT, 'Invoice.BillAddr.City'
DECLARE @InvoiceBillAddrCountry nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrCountry OUT, 'Invoice.BillAddr.Country'
DECLARE @InvoiceBillAddrLine5 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrLine5 OUT, 'Invoice.BillAddr.Line5'
DECLARE @InvoiceBillAddrLine4 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrLine4 OUT, 'Invoice.BillAddr.Line4'
DECLARE @InvoiceBillAddrLine3 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrLine3 OUT, 'Invoice.BillAddr.Line3'
DECLARE @InvoiceBillAddrLine2 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrLine2 OUT, 'Invoice.BillAddr.Line2'
DECLARE @InvoiceBillAddrLine1 nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrLine1 OUT, 'Invoice.BillAddr.Line1'
DECLARE @InvoiceBillAddrPostalCode nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrPostalCode OUT, 'Invoice.BillAddr.PostalCode'
DECLARE @InvoiceBillAddrLat nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrLat OUT, 'Invoice.BillAddr.Lat'
DECLARE @InvoiceBillAddrLong nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrLong OUT, 'Invoice.BillAddr.Long'
DECLARE @InvoiceBillAddrCountrySubDivisionCode nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrCountrySubDivisionCode OUT, 'Invoice.BillAddr.CountrySubDivisionCode'
DECLARE @InvoiceBillAddrId nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceBillAddrId OUT, 'Invoice.BillAddr.Id'
DECLARE @InvoiceApplyTaxAfterDiscount int
EXEC sp_OAMethod @jsonResponse, 'BoolOf', @InvoiceApplyTaxAfterDiscount OUT, 'Invoice.ApplyTaxAfterDiscount'
DECLARE @InvoiceId nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @InvoiceId OUT, 'Invoice.Id'
DECLARE @time nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @time OUT, 'time'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'Invoice.Line'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jsonResponse, 'I', @i
EXEC sp_OAMethod @jsonResponse, 'StringOf', @Description OUT, 'Invoice.Line[i].Description'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @DetailType OUT, 'Invoice.Line[i].DetailType'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @SalesItemLineDetailTaxCodeRefValue OUT, 'Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value'
EXEC sp_OAMethod @jsonResponse, 'IntOf', @SalesItemLineDetailQty OUT, 'Invoice.Line[i].SalesItemLineDetail.Qty'
EXEC sp_OAMethod @jsonResponse, 'IntOf', @SalesItemLineDetailUnitPrice OUT, 'Invoice.Line[i].SalesItemLineDetail.UnitPrice'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @SalesItemLineDetailServiceDate OUT, 'Invoice.Line[i].SalesItemLineDetail.ServiceDate'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @SalesItemLineDetailItemRefName OUT, 'Invoice.Line[i].SalesItemLineDetail.ItemRef.name'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @SalesItemLineDetailItemRefValue OUT, 'Invoice.Line[i].SalesItemLineDetail.ItemRef.value'
EXEC sp_OAMethod @jsonResponse, 'IntOf', @LineNum OUT, 'Invoice.Line[i].LineNum'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @Amount OUT, 'Invoice.Line[i].Amount'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @Id OUT, 'Invoice.Line[i].Id'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @DiscountLineDetailDiscountAccountRefName OUT, 'Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.name'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @DiscountLineDetailDiscountAccountRefValue OUT, 'Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.value'
EXEC sp_OAMethod @jsonResponse, 'BoolOf', @DiscountLineDetailPercentBased OUT, 'Invoice.Line[i].DiscountLineDetail.PercentBased'
EXEC sp_OAMethod @jsonResponse, 'IntOf', @DiscountLineDetailDiscountPercent OUT, 'Invoice.Line[i].DiscountLineDetail.DiscountPercent'
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'Invoice.TxnTaxDetail.TaxLine'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jsonResponse, 'I', @i
EXEC sp_OAMethod @jsonResponse, 'StringOf', @DetailType OUT, 'Invoice.TxnTaxDetail.TaxLine[i].DetailType'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @Amount OUT, 'Invoice.TxnTaxDetail.TaxLine[i].Amount'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @TaxLineDetailNetAmountTaxable OUT, 'Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable'
EXEC sp_OAMethod @jsonResponse, 'IntOf', @TaxLineDetailTaxPercent OUT, 'Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @TaxLineDetailTaxRateRefValue OUT, 'Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value'
EXEC sp_OAMethod @jsonResponse, 'BoolOf', @TaxLineDetailPercentBased OUT, 'Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased'
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'Invoice.CustomField'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jsonResponse, 'I', @i
EXEC sp_OAMethod @jsonResponse, 'StringOf', @StringValue OUT, 'Invoice.CustomField[i].StringValue'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @Type OUT, 'Invoice.CustomField[i].Type'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @Name OUT, 'Invoice.CustomField[i].Name'
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @sbAuth
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jsonResponse
END
GO