在nopcommerce V3.60中连接到我的Quickbook API V3 Sandbox公司时收到错误代码400错误请求?

时间:2015-07-08 08:55:07

标签: asp.net-mvc quickbooks quickbooks-online

我使用API​​密钥和令牌将订单项发送到quickbooks沙盒帐户。当我从在线搜索产品时,它会将错误代码400异常作为错误请求。

 // Sending Order Item To Quickbook Online Account   
        [NonAction]
            public void PostOrderPOS(Order order)
            {
            string accessToken = "qyprd9yjd4unMlR3ZCrCW8ZfdJS9WwTgm71oh3T2PZBSc8cB";
            string accessTokenSecret = "srsBYb9iYnYYWfJaXxL4zLaVJJl8HPfW0AN3sWra";
            string consumerKey = "qyprdWz4VaG2kND4E1AEhQaUFCchpM";
            string consumerSecret = "bVoRmlN4y7H5cg9NA0oV27pQYB9bzsuCmiYurt70";
            OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
            string appToken = "bd0a230bb9dc9b4321ba9feb899e18471d58";
            string companyID = "1403414765";  // realm
            ServiceContext context = new ServiceContext(appToken, companyID, IntuitServicesType.QBD, oauthValidator);
            DataService service = new DataService(context);

            Invoice inv = new Invoice();
            inv.AutoDocNumber = true;
            inv.AutoDocNumberSpecified = true;

            Line[] lines = new Line[order.OrderItems.Count + 2];
            int count = 0;
            foreach (var orderItem in order.OrderItems)
            {
            Line line2 = new Line();
            line2.Description = orderItem.Product.GetLocalized(x => x.Sku);
            line2.DetailType = LineDetailTypeEnum.SalesItemLineDetail;
            line2.DetailTypeSpecified = true;
            line2.Amount = _currencyService.ConvertCurrency(orderItem.PriceExclTax, order.CurrencyRate);
            line2.AmountSpecified = true;

            Item qboItem = new Item();
            var productname = orderItem.Product.GetLocalized(x => x.Name).ToLower();

            IEnumerable<Item> qboItems = service.FindAll(qboItem).Where(x => x.Name.ToLower() == productname) as IEnumerable<Item>; // ***-- Here i Am Getting Error***

            int productid = 0;
            if (qboItems.Count() > 0)
            {
            productid = Convert.ToInt32(qboItems.FirstOrDefault().Id);
            }
            else
            {
            Item product = new Item();
            product.Name = orderItem.Product.GetLocalized(x => x.Name);
            product.Description = orderItem.Product.GetLocalized(x => x.Sku);
            product.Active = true;
            product.ActiveSpecified = true;
            product.AssetAccountRef = new ReferenceType()
            {
            name = "Inventory Asset",
            Value = "54"
            };

            product.UnitPrice = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
            product.UnitPriceSpecified = true;
            product.Type = ItemTypeEnum.Inventory;
            product.TypeSpecified = true;

            ReferenceType refProduct = new ReferenceType();
            refProduct.name = "Sales of Product Income";
            refProduct.Value = "52";
            product.IncomeAccountRef = refProduct;
            var addedproduct = service.Add(product);
            productid = Convert.ToInt32(addedproduct.Id);

            }
            }

            inv.ShipDate = DateTime.Now.AddDays(7);
            inv.ShipDateSpecified = true;

            Invoice invoiceAdded = service.Add(inv);
            }

1 个答案:

答案 0 :(得分:0)

在serviceContext中将此行IntuitServicesType.QBD更改为IntuitServicesType.QBO