Question

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>    
Was it helpful?

Solution

Tax model for US vs Global is different. https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/020_key_concepts/global_tax_model

Looking at your code, I'm not sure if you want to set an invoice for global or not. Please clarify that.

If you want to create an invoice for US, then please refer the following code sample: https://gist.github.com/IntuitDeveloperRelations/6500373

If it is for global, then please read the docs link above and set the required properties accordingly. The tax ref for global is different than for US. As you mentioned, you can create an Invoice from UI and then read it and add properties for your Invoice. Also notice there are some properties that end with 'specified'. You need to set them too for the respective elements to be added in your payload.

I would suggest you to enable request/response logging from SDK so that it is easier for you to debug which properties are not sent in your request. https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0150_ipp_.net_devkit_3.0/logging

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top