brimstone brimstone - 11 months ago 98
Swift Question

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?

Answer Source

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 covert that to swift(using OAuthSwift or any other suitable lib). How to call API (Oauth 1.0)?

Thanks

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download