使用 Ruby 和 httparty 为 Quickbooks Online 和 Intuit Anywhere 创建记录示例?

发布于 2025-01-03 00:03:43 字数 2129 浏览 2 评论 0原文

有人可以发布一个使用 ruby​​ 和 httparty 在 Quickbooks online / intuit 中创建记录的示例吗?

我正在使用 intuit 与任何地方的 ruby​​ on Rails 应用程序集成,并且在尝试创建新记录时遇到了 POST 请求的问题。我已经能够使用 POST 命令成功检索数据(客户),该命令不需要请求正文中的 XML 数据,但在尝试创建具有需要传入的必需字段的新记录时遇到了麻烦请求正文中的 XML。

在我尝试为其创建记录的任何实体中,我都会遇到同样的错误:无效或缺少必填字段。在我看来,正文中的 XML(添加了必填字段的数据)要么被忽略(格式不正确?),要么没有被附加。

我希望熟悉 ruby​​ 的其他人可以发布使用 httparty 创建记录的示例。如果我能了解如何使用 httparty 正确传递 XML,我就可以自己解决我的问题。

我一直在使用 customer.com 示例(https://code.intuit.com/integration/viewvc/viewvc.cgi/IntuitAnywhere-Ruby/customer.com/?root=intuitanywhere&system=exsy1003)大部分如发布的那样,需要进行一些不相关的修改才能使其在 Rails 3.1 中工作。我正在使用示例中提供的数据拉取和处理,它看起来像一个使用 httparty 构建的相当标准的 API 包装器。

我使用的拉取类似于在 company_controller 客户方法中找到的拉取。以下是我尝试提交 XML 的两种不同方法:

#########################################
#Example 1 - XML

e = @company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{@company.realm}",
    { :body => 
        "<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\">
            <Name>Test Account 2</Name>
            <Desc>Test Account</Desc>
            <Subtype>Savings</Subtype>
            <AcctNum>5001</AcctNum>
            <OpeningBalanceDate>2010-05-14</OpeningBalanceDate>
        </Account>",
    :headers => {
        "Content-Type" => "application/xml"
    }}
)

#########################################
#Example 2 - hash

e = @company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{@company.realm}",
    { :body => { 
        :Account => {
            :Name => "Loan Account 2",
            :Desc  => "Loac Account 2",
            :Subtype     => "Savings",
            :AcctNum    => "5001",
            :OpeningBalanceDate    => "2011-04-22"
        }
    },
    :headers => {
        "Content-Type" => "application/xml"
    }}
)

Can someone post an example of creating a record in quickbooks online / intuit anywhere, using ruby and httparty?

I am working on an integration to a ruby on rails app using intuit anywhere, and am running into an issue with my POST request when attempting to create a new record. I have been able to successfully retrieve data (customers) using a POST command that doesn't require XML data in the body of the request, but am running into trouble when trying to create new records that have required fields that need to be passed in XML in the body of the request.

I get the same flavor of error in any entity for which I try to create a record for: an invalid or missing required field. It seems to me that the XML in the body (where the data for the required fields is added) is either being ignored (incorrect formatting?) or is not being attached.

I was hoping the someone else familiar with ruby could post an example of a record creation using httparty. If I could see how to correctly pass the XML using httparty, I can fix my problem myself.

I have been using the customer.com example (https://code.intuit.com/integration/viewvc/viewvc.cgi/IntuitAnywhere-Ruby/customer.com/?root=intuitanywhere&system=exsy1003) mostly as posted, with a few irrelevant modifications needed to get it to work in Rails 3.1. I am using the data pull and handling provided in the example, which looks like a pretty standard API wrapper built using httparty.

I am using a pull similar to the one found in the company_controller customers method. Here are two different ways I have tried submitting the XML:

#########################################
#Example 1 - XML

e = @company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{@company.realm}",
    { :body => 
        "<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\">
            <Name>Test Account 2</Name>
            <Desc>Test Account</Desc>
            <Subtype>Savings</Subtype>
            <AcctNum>5001</AcctNum>
            <OpeningBalanceDate>2010-05-14</OpeningBalanceDate>
        </Account>",
    :headers => {
        "Content-Type" => "application/xml"
    }}
)

#########################################
#Example 2 - hash

e = @company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{@company.realm}",
    { :body => { 
        :Account => {
            :Name => "Loan Account 2",
            :Desc  => "Loac Account 2",
            :Subtype     => "Savings",
            :AcctNum    => "5001",
            :OpeningBalanceDate    => "2011-04-22"
        }
    },
    :headers => {
        "Content-Type" => "application/xml"
    }}
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疧_╮線 2025-01-10 00:03:43

我错误地认为 intuit 提供的 customer.com 示例使用 httparty gem 进行 POST 调用,因此我使用了错误的语法。他们实际上使用 OAuth gem 的 POST 调用,其语法可以在这里找到: http: //oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html

我还必须修改标头以使 Intuit Anywhere 服务接受 XML 正文。下面是最终让我在任何地方使用 intuit 在 Quickbooks Online 中创建记录的代码:

    e = @company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{@company.realm}", "<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\"><Name>Test Account </Name><Desc>Test Account</Desc><Subtype>Savings</Subtype><AcctNum>5002</AcctNum><OpeningBalanceDate>2010-05-14</OpeningBalanceDate></Account>", {"Content-Type" => "application/xml", "standalone" => "yes", "encoding" => "UTF-8"})

I incorrectly assumed the customer.com example provided by intuit was using the httparty gem to make the POST call, so I was using the wrong syntax. They are actually using the OAuth gem's POST call, who's syntax can be found here: http://oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html

I also had to modify the headers to get the Intuit Anywhere service to accept the XML body. Here is the code that finally worked for me to create a record in quickbooks online using intuit anywhere:

    e = @company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{@company.realm}", "<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\"><Name>Test Account </Name><Desc>Test Account</Desc><Subtype>Savings</Subtype><AcctNum>5002</AcctNum><OpeningBalanceDate>2010-05-14</OpeningBalanceDate></Account>", {"Content-Type" => "application/xml", "standalone" => "yes", "encoding" => "UTF-8"})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文