使用.NET IPP QBOV3 SDK
我整个星期都在一个小型集成项目上工作(努力)。该项目的目的是能够在Windows桌面客户端应用程序和在线快速书之间集成一些帐户。
我希望能够 -
在阅读了几篇论坛和文章之后,了解QBOV3 .NET SDK就是其中之一,原因有两个。
所以,我的第一个障碍是OAuth - 最终我设法弄清楚了。我现在可以授权并连接到我的QBO沙盒帐户 - 太棒了!
我也可以从winforms应用程序创建客户,它们出现在QBO中 - 也很棒!
下一步,我在最后2个左右难倒,就是能够为客户创建发票 - 我似乎无法弄清楚要做什么。我经常收到“错误请求”错误。
我在网上没有找到关于如何从c#winforms应用程序执行此操作的示例。它不能那么难 - 所以我现在真的在踢自己。
任何帮助,或样本让我朝着正确的方向,将不胜感激。我不能相信没有这方面的简单例子 - 我想很少有人通过桌面winforms应用程序这样做,或者我只是在寻找错误的地方 - 或者错过了一些明显的东西!
阅读API文档令人困惑,并没有提供任何示例代码。我认为添加销售发票将是一件非常重要的事情。
这是我目前用来获得一些简单功能的代码 - 创建客户工作正常(如果客户在qbo中不存在 - 这是我需要在添加之前检查的东西 - 所以任何引导都会很好)
这是我到目前为止拼凑的代码..
private void button2_Click(object sender, EventArgs e)
{
string consumerKey = "consumerKey";
string consumerSecret = "consumerSecret";
string accessToken = "accessToken";
string accessTokenSecret = "accessTokenSecret";
string appToken = "appToken";
string companyID = "companyID"; //realmID
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
ServiceContext context = new ServiceContext(appToken, companyID, IntuitServicesType.QBO, oauthValidator);
//uses production as default, which is https://quickbooks.api.intuit.com
context.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/";
//If not set, the default base URL, https://quickbooks.api.intuit.com, is used
DataService service = new DataService(context);
//add customer
Customer customer = new Customer();
customer.CompanyName = "Jims Junk";
customer.GivenName = "Jim";
customer.FamilyName = "Little";
customer.PrimaryEmailAddr = new EmailAddress() { Address = "[email protected]", Default = true };
customer.DisplayName = "Jims Junk Ltd"
Customer resultCustomer = service.Add(customer) as Customer;
//invoice
//-An invoice must have at least one Line that describes an item.
//- An invoice must have CustomerRef populated.
//- The DocNumber attribute is populated automatically by the data service if not supplied.
//- If ShipAddr, BillAddr, or both are not provided, the appropriate customer address from Customer is used to fill those values.
//-DocNumber, if supplied, must be unique.
Invoice invoice = new Invoice();
invoice.DocNumber = "uniqueNumber";
invoice.TxnDate = DateTime.Today.Date;
invoice.TxnDateSpecified = true;
invoice.CustomerRef = new ReferenceType()
{
name = customer.DisplayName,
Value = resultCustomer.Id
};
Line invLine = new Line();
invLine.Amount = 10000;
invLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail;
invLine.Description = "Test Product";
invoice.Line = new Line[] { invLine };
Invoice resultInvoice = service.Add(invoice) as Invoice;
}
Sods Law,几天没找到任何东西 - 刚才我找到了一个有帮助的代码示例。
我现在设法将发票寄到QBO。
这是帮助的链接 - http://developer.qbapi.com/Create-Invoice-Error---Bad-Request.aspx
生病只是留在这里,以便其他人可以受益,如果挣扎。
谢谢阅读。