toddgeist
toddgeist

Reputation: 902

how to connect node js to quickbooks v3 REST API

I am trying to connect to Intuits v3 REST api, using node.js. I am using SuperAgent and superagent-oauth to make the requests. I generated the access tokens using Intuits Oauth playground. But I keep getting "ApplicationAuthenticationFailed; errorCode=003200; statusCode=401"

This is what I am using.

var  OAuth = require('oauth')
,request = require('superagent');
require('superagent-oauth')(request);
var oauth = new OAuth.OAuth('','', consumerKey, consumerSecret, '1.0.A', null, 'HMAC-SHA1')  

request.get("https://quickbooks.api.intuit.com/v3/company/672198300/customer/102")
.set('Content-Type', 'text/plain')
.accept('json')
.sign(oauth,accessToken,accessTokenSecret )
.end(function (err, res) {
    console.log(res.text)
})

and here is the response

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <IntuitResponse time="2014-06-14T18:33:49.228-07:00" xmlns="http://schema.intuit.com/finance/v3">
<Fault type="AUTHENTICATION">
    <Error code="3200">
        <Message>message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401</Message>
    </Error>
</Fault>

Can anyone shed any light on what is happening?

Upvotes: 1

Views: 2780

Answers (3)

Michael Cohen
Michael Cohen

Reputation: 131

You could use the node.js client library

Like most other clients, that would save you from manually building http requests. Just provide the application credentials and the individual user credentials and you can simply call methods on a Javascript object. All of the REST endpoints have corresponding methods on the QuickBooks object, which follows node.js convention and takes an optional callback as the last argument.

Upvotes: 4

toddgeist
toddgeist

Reputation: 902

SOlVED!

I used Postman to create the request. And it worked. Then I checked the oAuth header Postman had generated against the one I was generating with node ( I used requestBin to see the header of my request ). I discovered that the only real difference was that I was using "1.0A" as the version. Changing that to "1.0" worked!

var oauth = new OAuth.OAuth('','', consumerKey, consumerSecret, '1.0', null, 'HMAC-SHA1')

Upvotes: 2

nimisha shrivastava
nimisha shrivastava

Reputation: 2367

I do not have anything for ou in node.js but can provide you with raw request and response for the calls. Compare your raw requests against this. The signature should be double encoded. Get Request token call-

GET https://oauth.intuit.com/oauth/v1/get_request_token?oauth_callback=oob&oauth_nonce=34562646-ab97-46e1-9aa7-f814d83ef9d1&oauth_consumer_key=qyprd7I5WvVgWDFnPoiBh1ejZn&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1392306961&oauth_version=1.0&oauth_signature=0EtvSnzsuumeyib2fiEcnSyu8%3D HTTP/1.1 Host: oauth.intuit.com

HTTP/1.1 200 OK Date: Thu, 13 Feb 2014 15:56:03 GMT Server: Apache Cache-Control: no-cache, no-store Pragma: no-cache Content-Length: 150 Connection: close Content-Type: text/plain

oauth_token_secret=dXhHHMS1EfdrQ32UabOMscIRWt5bLJNX3ZKljjBc&oauth_callback_confirmed=true&oauth_token=qyprdbwXdWrAt0xM2NgkLlJ79yCp4I2SmDg7tahDBPjA6Wti

Get Access Token-

GET https://oauth.intuit.com/oauth/v1/get_access_token?oauth_verifier=b4skra3&oauth_token=qyprde5fvI7WNOQjTKYLDzTVxJ2dLPTgQEQSPlDVGxEy9wZX&oauth_nonce=f20a5a4b-3635-40a8-92cf-697dfdb07b9d&oauth_consumer_key=qyprd7I5WvVgJZUvWDFnPoiBh1ejZn&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1392397399&oauth_version=1.0&oauth_signature=gEVHttlM8IBAAkmi1dSNJgkKGsI%3D HTTP/1.1 Host: oauth.intuit.com

HTTP/1.1 200 OK Date: Fri, 14 Feb 2014 17:03:20 GMT Server: Apache Cache-Control: no-cache, no-store Pragma: no-cache Content-Length: 120 Connection: close Content-Type: text/plain

oauth_token_secret=474gtp6xsFzNJ1EhrrjiHrTH96xXieaRLinjPomA&oauth_token=qyprdNIpWn2oYPupMpeH8Byf9Bhun5rPpIZZtTbNsPyFtbT4

Upvotes: 0

Related Questions