I'm using the .NET SDK with v3 of the QBO API. I can create an invoice just fine, but when I try to include tax information it fails every time. As you can see in the code below, I'm first looking up the tax rate in QBO, and only specifying it in the invoice if it already exists in QBO. (btw, anybody know when will we be able to create new tax rates via the API?)
Due to the lack of clarity in the API docs, I queried an invoice from QBO then looked at it's properties to try to figure out which properties need to be set.
//assume I already have an Intuit Invoice object named qbInvoice
string taxName = ValueLists.GetTaxCode(objSR.TaxCodeId);
var qbTaxRate = (new QueryService<Intuit.Ipp.Data.TaxRate>(qbContext)).ExecuteIdsQuery(String.Format("SELECT * FROM TaxRate WHERE Name = '{0}'", taxName), QueryOperationType.query);
if (qbTaxRate.Count > 0)
{
QBAPI.Line taxLine = new QBAPI.Line()
{
Amount = sr.TaxAmount,
AmountSpecified = true,
DetailType = QBAPI.LineDetailTypeEnum.TaxLineDetail,
DetailTypeSpecified = true,
AnyIntuitObject = new QBAPI.TaxLineDetail()
{
NetAmountTaxable = objSR.TaxableAmount,
NetAmountTaxableSpecified = true,
PercentBased = true,
PercentBasedSpecified = true,
TaxPercent = sr.TaxRate,
TaxPercentSpecified = true,
TaxRateRef = new QBAPI.ReferenceType()
{
Value = qbTaxRate.First().Id
}
}
};
qbInvoice.GlobalTaxCalculation = QBAPI.GlobalTaxCalculationEnum.TaxInclusive;
qbInvoice.GlobalTaxCalculationSpecified = true;
qbInvoice.TxnTaxDetail = new QBAPI.TxnTaxDetail()
{
TaxLine = new QBAPI.Line[] { taxLine },
TotalTax = sr.TaxAmount,
TotalTaxSpecified = true,
TxnTaxCodeRef = new QBAPI.ReferenceType()
{
Value = qbTaxRate.First().Id
}
};
}
When using the code above to specify tax information, I get the following error:
Error Code: 6000,
A business validation error has occurred while processing your request - Business Validation Error: We're sorry, QuickBooks encountered an error while calculating tax. Try reselecting the tax rate or reentering the product/service item and saving the form again. <a href='https://support.qbo.intuit.com/support/answers.cfm?faq_id=5558&locale=en_US' target="_blank" title="Help">Please click here for more information</a>