Question

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"
    }}
)
Was it helpful?

Solution

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"})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top