Search code examples
phpxcodeswiftquickbooksintuit-partner-platform

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?


Solution

  • 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)?