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.
[company_number]from the request URL with the correct company number, and also [consumer_key] with correct consumer key. - vincent