Search code examples
xcodeswiftoauthquickbooksintuit-partner-platform

Xcode Swift Quickbooks call


I want to do an API request to my Quickbooks company, but I'm having some issues. Every time I try to connect, I get an error saying "The operation can't be completed": error 1012. I searched it up, and this error has to do with the OAuth tokens being wrong. I do not know which tokens to put in the following headers:

    var request = NSMutableURLRequest(URL: NSURL(string: "https://quickbooks.api.intuit.com/v3/company/myCompanyId/query?query=SELECT%2A%20FROM%20Customer")!)

    request.HTTPMethod = "GET"

    request.setValue("secret", forHTTPHeaderField: "oauth_token")
    request.setValue("secret", forHTTPHeaderField: "app_token")
    request.setValue("secret", forHTTPHeaderField: "oauth_consumer_key")
    request.setValue("D3jdR1LMb5T2mF0yggcgHsYjVjs%3D", forHTTPHeaderField: "oauth_signature")
    request.setValue("HMAC-SHA1", forHTTPHeaderField: "oauth_signature_method")
    request.setValue("1424984263", forHTTPHeaderField: "oauth_timestamp")
    request.setValue("1.0", forHTTPHeaderField: "oauth_version")
    request.setValue("f3b666ee-2d2a-42a1-81b3-8370b74c4c3a", forHTTPHeaderField: "oauth_nonce")


    println(request.allHTTPHeaderFields!)
    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
        (response, data, error) in

        println(response)
        println(error)
        println(data)

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

Can anybody tell me where to find the correct keys for these values? I can only find keys for app token, oauth consumer key, and oath consumer key secret. Where do these values go too?


Solution

  • Using consumerKey and consumerSecret , 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.