gpt4 book ai didi

c# - QBO SDK C# - 异步批处理创建多个客户

转载 作者:太空宇宙 更新时间:2023-11-03 13:40:25 25 4
gpt4 key购买 nike

我想插入多个客户对象我点击了这个链接https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0100_ipp_.net_devkit/0300_asynchronous_calls/2_batch_process但出现以下错误 - “您一次只能添加或编辑一个名称。请重试。”


发布我的代码:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Web;
using Intuit.Ipp.Core;
using Intuit.Ipp.Security;
using Intuit.Ipp.Services;
using HelloIntuitAnywhere.Utilities;
using Intuit.Ipp.Data.Qbo;
using Intuit.Ipp.Data.Extensions;
using System.Linq;
using System.IO;
using Intuit.Ipp.Data;

namespace HelloIntuitAnywhere
{
public partial class BatchRequest : System.Web.UI.Page
{
public delegate IntuitBatchResponse DelegateBatchCompleted(IntuitBatchRequest batchRequest);
protected void Page_Load(object sender, EventArgs e)
{

if (HttpContext.Current.Session.Keys.Count > 0)
{
String realmId = HttpContext.Current.Session["realm"].ToString();
String accessToken = HttpContext.Current.Session["accessToken"].ToString();
String accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
String consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(CultureInfo.InvariantCulture);
String consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString(CultureInfo.InvariantCulture);
IntuitServicesType intuitServiceType = (IntuitServicesType)HttpContext.Current.Session["intuitServiceType"];

OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
ServiceContext context = new ServiceContext(oauthValidator, realmId, intuitServiceType);
DataServices commonService = new DataServices(context);

try
{
switch (intuitServiceType)
{
case IntuitServicesType.QBO:

IntuitBatchRequest batchRequest = new IntuitBatchRequest();
batchRequest.BatchItem = new BatchItemRequest[10];

for (int i = 0; i < 10; i++)
{
Item itm1 = CreateItem("it8" + i.ToString());
string guid = Guid.NewGuid().ToString("N");
guid = guid.Substring(0, 30);
guid = i.ToString();
BatchItemRequest itm1BatchItem = new BatchItemRequest();
itm1BatchItem.bId = guid;
itm1BatchItem.Item = itm1;
itm1BatchItem.operation = OperationEnum.create;
itm1BatchItem.operationSpecified = true;
batchRequest.BatchItem[i] = itm1BatchItem;
}



//IntuitBatchResponse batchResponse = commonService.ExecuteBatch<IntuitBatchRequest>(batchRequest);
try
{
DelegateBatchCompleted delegateBatch = new DelegateBatchCompleted(commonService.ExecuteBatch<IntuitBatchRequest>);
IAsyncResult result = delegateBatch.BeginInvoke(batchRequest, new AsyncCallback(CallbackMethod), delegateBatch);
}
catch (Exception ex)
{
throw ex;
}


break;

default:
throw new Exception("Data Source not defined.");
}


}
catch
{
throw;
}
}
}

private Intuit.Ipp.Data.Qbo.Item CreateItem(string str)
{
Intuit.Ipp.Data.Qbo.Item item = new Intuit.Ipp.Data.Qbo.Item();

item.Desc = str + "Test Desc";
item.Name = str + "Test Name";
item.Taxable = true;
item.TaxableSpecified = true;
item.ExternalKey = new Intuit.Ipp.Data.Qbo.IdType() { idDomain = Intuit.Ipp.Data.Qbo.idDomainEnum.QBO, Value = str + "123" };
item.UnitPrice = new Intuit.Ipp.Data.Qbo.Money() { Amount = 6, AmountSpecified = true, CurrencyCode = Intuit.Ipp.Data.Qbo.currencyCode.AED, CurrencyCodeSpecified = false };

item.IncomeAccountRef = new Intuit.Ipp.Data.Qbo.AccountRef() { AccountId = new Intuit.Ipp.Data.Qbo.IdType() { idDomain = Intuit.Ipp.Data.Qbo.idDomainEnum.QBO, Value = "1" }, AccountType = Intuit.Ipp.Data.Qbo.AccountTypeEnum.Asset, AccountTypeSpecified = true };

item.Type = Intuit.Ipp.Data.Qbo.ItemTypeEnum.Assembly;

return item;
}

static void CallbackMethod(IAsyncResult result)
{
DelegateBatchCompleted delegateBatch = (DelegateBatchCompleted)result.AsyncState;
IntuitBatchResponse batchResponse = delegateBatch.EndInvoke(result);
}


}
}

最佳答案

错误信息很清楚:Quickbooks API 一次只允许编辑一个客户。

他们可能会锁定 Customer 表,因为业务层或底层数据模型都不支持并发编辑。

鉴于此限制,我看不到解决此问题的方法。

它们允许您异步调用同步方法,因此您不必阻塞直到方法完成,但这并不意味着您可以同时进行两个客户编辑。但是,您可以在编辑完成时做其他工作。

关于c# - QBO SDK C# - 异步批处理创建多个客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17229636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com