0
votes

I've been messing around with this for days now, I've searched and found some variations, but nothing here or on the Intuit boards to make this work. I've tried escaping the single quotes in various ways:

select id from invoice where docnumber = %27[docnumber]%27

select%20id%20from%20invoice%20where%20docnumber%3E%27[docnumber]%27%

select id from invoice where docnumber like \'%1038%\' 

as well as and combined with, using http_build_query, urlencode and rawurlencode. I am a bit of a cURL newbie, it's probably something obvious.

This works and returns values I expect (but as a single long string):

$curl = curl_init();

$url = "https://sandbox-quickbooks.api.intuit.com/v3/company/[company_number]/query?";
$sqlQueryString = http_build_query(array("query" => "select id from invoice"), ' ', ';'); 
$url = $url . $sqlQueryString;

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_HTTPHEADER => array( 
    "" . $qbo_token,
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

This (with docnumber = 'xxxx' in the query) fails with an Authentication Error, see below the code:

$curl = curl_init();

$url = "https://sandbox-quickbooks.api.intuit.com/v3/company/[company_number]/query?";
$sqlQueryString = http_build_query(array("query" => "select id from invoice where docnumber = '[docnumber]'"), ' ', ';'); 
$url = $url . $sqlQueryString;

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_HTTPHEADER => array( 
    "" . $qbo_token,
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401 SignatureBaseString: GET&https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%2F[company_number]%2Fquery&oauth_consumer_key%3D[consumer_key]%26oauth_nonce%3DyIxOgk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1448731643%26oauth_token%3D[token]%26oauth_version%3D1.0%26query%3Dselect%2520id%2520from%2520invoice%2520where%2520docnumber%2520%253D%2520%2527[docnumber] "

Both of the query strings work in the Intuit / QuickBooks APIExplorer and return a JSON response. I don't know why I'm getting a string response from PHP cUrl for the first query (the one that works), but I really need the second query to work and I'll take any kind of response I can get other that Authentication error.

1
i believe you will need to replace this [company_number] from the request URL with the correct company number, and also [consumer_key] with correct consumer key. - vincent
I put those in the question to keep from exposing sensitive info. I did note that the first code snippet works. - kmw042

1 Answers

0
votes

From the error message you have posted, I can find there & instead of ? after the /query. That's why your authentication/authorization parameters are not working here.

http://...[company_number]%2Fquery&oauth_consumer_key
                                  ^

Actual should be:

http://... company_number]%2Fquery?oauth_consumer_key
                                  ^

Though your code is showing you are using /query? in your code at the description, but I believe in your real code you are somehow changing this into &.

You can use CURLOPT_VERBOSE => true, in your code to debug the curl request by yourself also.