brimstone
brimstone

Reputation: 3400

Call Quickbooks API

I want to be able to call the Quickbooks API for a test app I've made on Intuit Developer. The app is made in Xcode, using Swift, here's what I have so far:

    var request = NSMutableURLRequest(URL: NSURL(string: "https://quickbooks.api.intuit.com/v3/company/1313821405/query?query=SELECT%20*%20FROM%20Customer")!)
    request.HTTPMethod = "GET"
    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
        (response, data, error) in

        println(response)
        println(data)
        println(error)
        if error == nil {
            if let HTTPResponse = response as? NSHTTPURLResponse {
                let statusCode = HTTPResponse.statusCode
                if statusCode == 200 {
                    println("success")

                }
            }
        }
    }

The error says that "The operation couldn't be completed". I'm doing this in a Sandbox Company, is this the reason why? If I entered a real company ID would it work? Also, how can I use the API?

Upvotes: 0

Views: 738

Answers (2)

Manas Mukherjee
Manas Mukherjee

Reputation: 5340

There is no way to generate tokens entirely from your mobile app.

Using consumerKey and consumerToken, you can generate accessToken and accessSecret from the OAuthPlayground. https://appcenter.intuit.com/Playground/OAuth/IA PN - After completing C2QB(OAuth) flow, you should use 'App Menu API Test.' option which will show you accessToken and accessSecret.

After getting those 4 tokens, you can make any calls. For that you should use any standard OAuth lib (Swift) like https://github.com/dongri/OAuthSwift PN - I've not tried it yet (I just found it after doing a lil search in net).

PFB post where I'd shared Java code which used signPost OAuth lib. You can convert that to Swift (using OAuthSwift or any other suitable lib). How to call API (Oauth 1.0)?

Upvotes: 1

nimisha shrivastava
nimisha shrivastava

Reputation: 2367

https://developer.intuit.com/docs/0100_accounting/0060_authentication_and_authorization

Have you authenticated your request using Oauth 1.0 and got the access token and access token secret to make api calls? You need to have a web page which implements Connect to Quickbooks button and then get these tokens for the QBO company you want to connect to. Then only you can make the calls to the api.

[EDIT]- 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


[EDIT]- Raw req and response for making api calls- POST https://quickbooks.api.intuit.com/v3/company/717093040/query HTTP/1.1

Content-Type: text/plain

Host: quickbooks.api.intuit.com

Authorization: OAuth oauth_token="lvprdBmi45KMPO2FnvYtq6KLFTMM7KG0P0PJO3Sm7F3n7pgq",oauth_nonce="e5d6e732-f903-4456-9c5f-58103843c3c6",oauth_consumer_key="qyprd7I5WvVgJZUvWDFnPoiBh1ejZn",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1394005668",oauth_version="1.0",oauth_signature="J8qgGZRa4loR6HEtdpAudP1nVpw%3D"

Content-Length: 47 Expect: 100-continue Connection: Keep-Alive

Select * From Account

HTTP/1.1 200 OK

Date: Wed, 05 Mar 2014 07:47:49 GMT

Server: Apache/2.2.3 (Red Hat)

HeaderQueryTime: 21

ContextInitTime: 12

HeaderDAOTime: 22

Response-Id: 146f271e-1f23-4842-87ba-ad9fc69fe0a2

Response-App-Time: 196

intuit_tid: 146f271e-1f23-4842-87ba-ad9fc69fe0a2

Connection: close

Content-Type: application/xml

Content-Length: 36683

<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-03-    05T07:47:49.393Z"><QueryResponse maxResults="64" startPosition="1"><Account     status="Pending"><Id>QB:9</Id><SyncToken>7</SyncToken><MetaData>    <CreateTime>2014-03-03T10:56:45Z</CreateTime><LastUpdatedTime>2014-03-    04T14:44:57Z</LastUpdatedTime></MetaData><Name>Name_updatedc4f1a</Name>    <SubAccount>false</SubAccount>   <Description>description_updatedfc6b1</Description><Active>true</Active>    <Classification>Revenue</Classification><AccountType>Income</AccountType>    <AcctNum>49400</AcctNum><CurrentBalance>22654.7</CurrentBalance>   <OnlineBankingEnabled>false</OnlineBankingEnabled></Account></QueryResponse>   </IntuitResponse>

Upvotes: 1

Related Questions