连接ASP.NET应用程序QuickBooks的在线版 [英] Connecting an ASP.NET application to QuickBooks Online Edition

查看:120
本文介绍了连接ASP.NET应用程序QuickBooks的在线版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个连接到QuickBooks的在线版ASP.NET页面,阅读一对夫妇的价值观,并显示结果。到目前为止,我已经下载了SDK QuickBooks的,但我一直无法找到关于如何创建一个asp.net页面连接到QuickBooks的在线简单的一步一步的例子。 QuickBooks的SDK文档和SDK本身是非常混乱,而且势不可挡。任何人都知道一个简单的教程一步一步的在哪里开始...也许上的第一件事暗示的事。


解决方案

下面都是我走上得到这个工作的步骤。特别感谢基思·帕尔默他的意见,答案,的他的网站这真的帮了我得到这个工作。


  1. 位于 HTTP注册应用程序:// AP preg.quickbooks.com 。这会给你的应用程序ID和应用程序名称。我用这些设置:


    • 目标应用:QBOE

    • 环境:生产

    • 应用程序类型:台式机


      • (使用桌面让东西变得更容易,只要不需要证书)


    • 一个验证密钥发送给您需要此向导的第2页上输入您的电子邮件地址。



  2. 设置您的QBOE连接即可。一旦你完成步骤1中注册应用程序,您将有一个应用程序ID。在URL中使用低于这个ID来设置QBOE连接:

    • https://login.quickbooks.com/j/qbn/sdkapp/confirm?serviceid=2004&appid=<$c$c>APP_ID

    • 注:请务必将APP_ID在当你注册你的应用程序所创建的应用程序ID上述网址

    • 该向导将引导您完成以下步骤:

      1. 为您的连接指定一个名称。

      2. 授予访问权限 - 我给了所有的会计权利,因为这是最简单的

      3. 指定登录安全 - 我转身登录安全关。这一点很重要,因为它使提交XML到QBOE比较容易,因为你并不需要得到一个会话票证为每个用户。

      4. 您将被赋予一个连接密钥。



  3. 在这一点上,你现在拥有的信息在 3的重要棋子,以获得您的QuickBooks的在线版(QBOE)帐户的访问。

    • 应用程序名

    • 应用程序ID

    • 连接键


  4. 邮政XML来QBOE 的3个访问信息与实际要求到您的QBOE数据库。下面是示例C#code,将张贴到QBOE网关。这将返回所有客户在你的QuickBooks的数据库。请确保您的应用程序名称,应用程序ID和连接密钥更新下面的XML。

     字符串requestUrl = NULL;
    requestUrl =htt​​ps://apps.quickbooks.com/j/AppGateway;HttpWebRequest的WebRequestObject = NULL;
    StreamReader的SR = NULL;
    HttpWebResponse WebResponseObject = NULL;
    StreamWriter的SWR = NULL;尝试
    {
        WebRequestObject =(HttpWebRequest的)WebRequest.Create(requestUrl);
        WebRequestObject.Method =POST;
        WebRequestObject.ContentType =应用程序/ x-qbxml
        WebRequestObject.AllowAutoRedirect = FALSE;    后弦= @&LT; XML版本=1.0,编码=UTF-8&GT?;
        &LT; qbxml版本=6.0&GT?;
        &LT; QBXML&GT;
          &LT; SignonMsgsRq&GT;
            &LT; SignonDesktopRq&GT;
              &LT; ClientDateTime&GT; %% CLIENT_DATE_TIME %%&LT; / ClientDateTime&GT;
              &LT; ApplicationLogin&GT; APPLICATION_LOGIN&LT; / ApplicationLogin&GT;
              &LT; ConnectionTicket&GT; CONNECTION_TICKET&LT; / ConnectionTicket&GT;
              &LT;语言和GT;英语&LT; /语言与GT;
              &LT;&的AppID GT;&APP_ID LT; /&的AppID GT;
              &所述; AppVer→1&下; / AppVer&GT;
            &LT; / SignonDesktopRq&GT;
          &LT; / SignonMsgsRq&GT;
          &LT; QBXMLMsgsRq的onError =continueOnError&GT;
            &所述; CustomerQueryRq的requestId =2/&GT;
          &LT; / QBXMLMsgsRq&GT;
        &所述; / QBXML&gt;中;    后= post.Replace(%% CLIENT_DATE_TIME %%,DateTime.Now.ToString(YYYY-MM-DDTHH:MM:SS));
        XmlDocument的xmlDoc中=新的XmlDocument();
        xmlDoc.LoadXml(岗位);
        后= xmlDoc.InnerXml;
        WebRequestObject.ContentLength = post.Length;
        SWR =新的StreamWriter(WebRequestObject.GetRequestStream());
        swr.Write(岗位);
        swr.Close();
        WebResponseObject =(HttpWebResponse)WebRequestObject.GetResponse();
        SR =新的StreamReader(WebResponseObject.GetResponseStream());
        字符串结果= sr.ReadToEnd();
        }
    最后
        {
            尝试
            {
                sr.Close();
            }
            抓住
            {
            }        尝试
            {
                WebResponseObject.Close();
                WebRequestObject.Abort();
            }
            抓住
            {
            }
        }


  5. 几件事情要注意:


    • 正如基思·帕尔默指出qbxml版本需要6.0(即使在IDN统一屏幕显示参考7.0)

    • 我需要包括的onError =continueOnError属性。

    • 设置WebRequestObject.ContentLength属性是必需的。

    • 内容类型必须是应用程序/ x-qbxml

    • 最后,我收到了很多远程服务器返回错误:(400)错误的请求。其中的例外是没有帮助所有,但最后我能跟踪他们的东西不好的XML。所以,如果你得到这个异​​常期待您的XML作为问题的根源。


I am trying to create an ASP.NET page that connects to QuickBooks Online Edition, read a couple of values, and display the results. So far I have downloaded the QuickBooks SDK but I have been unable to find a simple step-by-step example on how to create an asp.net page to connect to QuickBooks Online. The QuickBooks SDK documentation and the SDK itself is very confusing and overwhelming. Anyone know of a simple step by step tutorial on where to get started... or maybe a hint on the very first thing to do.

解决方案

Here are all the steps I took to get this working. Special thanks to Keith Palmer for his comments, answers, and his website which really helped me get this working.

  1. Register your application at http://appreg.quickbooks.com. This will give you your App ID and Application Name. I used these settings:

    • Target Application: QBOE
    • Environment: Production
    • Application Type: Desktop

      • (using Desktop made things much easier as far as not needing certificates)
    • A verification key is sent to your email address which you need to enter on page 2 of this wizard.

  2. Set up your QBOE Connection. Once you finish registering your application in Step 1, you will then have an Application ID. Use this ID in the url below to set up your QBOE Connection:
    • https://login.quickbooks.com/j/qbn/sdkapp/confirm?serviceid=2004&appid=APP_ID
    • NOTE: Make sure to replace APP_ID in the above url with the Application ID that was created when you registered your application.
    • The wizard will take you through the following steps:

      1. Specifying a name for your connection.
      2. Granting Access Rights - I gave All Accounting rights since this was easiest.
      3. Specify Login Security - I turned Login Security Off. This is important since it makes submitting the xml to the QBOE much easier since you do not need to get a session ticket for each user.
      4. You will then be given a Connection Key.

  3. At this point you now have the 3 important pieces of information in order to gain access to your QuickBooks Online Edition (QBOE) account.
    • Application Name
    • Application ID
    • Connection Key
  4. Post the XML to QBOE with the 3 pieces of access information and the actual request into your QBOE database. Here is sample c# code that will post to the QBOE gateway. This will return all customers in your QuickBooks database. Make sure to update the xml below with your Application Name, Application ID, and Connection Key.

    string requestUrl = null;
    requestUrl = "https://apps.quickbooks.com/j/AppGateway";
    
    HttpWebRequest WebRequestObject = null;
    StreamReader sr = null;
    HttpWebResponse WebResponseObject = null;
    StreamWriter swr = null;
    
    try
    {
        WebRequestObject = (HttpWebRequest)WebRequest.Create(requestUrl);
        WebRequestObject.Method = "POST";
        WebRequestObject.ContentType = "application/x-qbxml";
        WebRequestObject.AllowAutoRedirect = false;
    
        string post = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
        <?qbxml version=""6.0""?>
        <QBXML>
          <SignonMsgsRq>
            <SignonDesktopRq>
              <ClientDateTime>%%CLIENT_DATE_TIME%%</ClientDateTime>
              <ApplicationLogin>APPLICATION_LOGIN</ApplicationLogin>
              <ConnectionTicket>CONNECTION_TICKET</ConnectionTicket>
              <Language>English</Language>
              <AppID>APP_ID</AppID>
              <AppVer>1</AppVer>
            </SignonDesktopRq>
          </SignonMsgsRq>
          <QBXMLMsgsRq onError=""continueOnError"">
            <CustomerQueryRq requestID=""2"" />
          </QBXMLMsgsRq>
        </QBXML>";
    
    
    
        post = post.Replace("%%CLIENT_DATE_TIME%%", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"));
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(post);
        post = xmlDoc.InnerXml;
        WebRequestObject.ContentLength = post.Length;
        swr = new StreamWriter(WebRequestObject.GetRequestStream());
        swr.Write(post);
        swr.Close();
        WebResponseObject = (HttpWebResponse)WebRequestObject.GetResponse();
        sr = new StreamReader(WebResponseObject.GetResponseStream());
        string Results = sr.ReadToEnd();
        }
    finally
        {
            try
            {
                sr.Close();
            }
            catch
            {
            }
    
            try
            {
                WebResponseObject.Close();
                WebRequestObject.Abort();
            }
            catch
            {
            }
        }
    

  5. Couple things to note:

    • As pointed out by Keith Palmer the qbxml version needs to be 6.0 (even though the IDN Unified On-Screen Reference shows 7.0)
    • I needed to include the onError="continueOnError" attribute.
    • Setting the WebRequestObject.ContentLength property is required.
    • Content Type needs to be "application/x-qbxml"
    • And finally I received many "The remote server returned an error: (400) Bad Request." exceptions which were not helpful at all but in the end I was able to trace them to something wrong with the xml. So if you get this exception look to your xml as the source of the problem.

这篇关于连接ASP.NET应用程序QuickBooks的在线版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆