无法使用.NET SDK将TaxService添加到QBO

时间:2015-01-31 23:26:22

标签: intuit-partner-platform quickbooks-online

如何使用API​​ v3和TaxService资源在QBO中创建税率?当我尝试以与任何其他对象相同的方式添加它时,Visual Studio给了我这个错误:"类型' Intuit.Ipp.Data.TaxService'不能用作类型参数' T'在泛型类型或方法Intuit.Ipp.DataService.DataService.Add(T)'。来自< Intuit.Ipp.Data.TaxService' Intuit.Ipp.Data.TaxService' to' Intuit.Ipp.Data.IEntity'。"

以下是代码:

Intuit.Ipp.Data.TaxService ts = new Intuit.Ipp.Data.TaxService();
// Populate fields here...
DataService ds = new DataService(ServiceContext);
Intuit.Ipp.Data.TaxService newTs = ds.Add<Intuit.Ipp.Data.TaxService>(ts);

1 个答案:

答案 0 :(得分:1)

仅使用GlobalTaxService端点和JSON格式。试试这段代码:

GlobalTaxService taxSvc = new GlobalTaxService(context);
            Intuit.Ipp.Data.TaxService taxCodetobeAdded = new Data.TaxService();
            taxCodetobeAdded.TaxCode = "taxC_" + Guid.NewGuid().ToString("N");

            QueryService<TaxAgency> taxagency = new QueryService<TaxAgency>(context);
            TaxAgency taxagencyResult = taxagency.ExecuteIdsQuery("select * from TaxAgency").FirstOrDefault<TaxAgency>();                          



            List<TaxRateDetails> lstTaxRate = new List<TaxRateDetails>();
            TaxRateDetails taxdetail1 = new TaxRateDetails();
            taxdetail1.TaxRateName = "taxR1_" + Guid.NewGuid().ToString("N");
            taxdetail1.RateValue = 3m;
            taxdetail1.RateValueSpecified = true;
            taxdetail1.TaxAgencyId = taxagencyResult.Id.ToString();
            taxdetail1.TaxApplicableOn = TaxRateApplicableOnEnum.Sales;
            taxdetail1.TaxApplicableOnSpecified = true;
            lstTaxRate.Add(taxdetail1);

            TaxRateDetails taxdetail2 = new TaxRateDetails();
            taxdetail2.TaxRateName = "taxR2_" + Guid.NewGuid().ToString("N");
            taxdetail2.RateValue = 2m;
            taxdetail2.RateValueSpecified = true;
            taxdetail2.TaxAgencyId = taxagencyResult.Id.ToString();
            taxdetail2.TaxApplicableOn = TaxRateApplicableOnEnum.Sales;
            taxdetail2.TaxApplicableOnSpecified = true;
            lstTaxRate.Add(taxdetail2);

            //TaxRateDetails taxdetail3 = new TaxRateDetails();
            //taxdetail3.TaxRateName = "rate298";
            //taxdetail3.TaxRateId = "2";

            //lstTaxRate.Add(taxdetail3);

            taxCodetobeAdded.TaxRateDetails = lstTaxRate.ToArray();

            Intuit.Ipp.Data.TaxService taxCodeAdded = taxSvc.AddTaxCode(taxCodetobeAdded);