When I run the Quickbooks Online API using 'Postman', it works fine. Postman automatically generates the nonce and oauth_signature value. But when I run the API using PHP, i got stuck with the following error.
message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401 SignatureBaseString: POST&https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%2F193514525%2Faccount&oauth_consumer_key%3DqyprdH7kq5iG34sV2fSaj9tKC1KzXG%26oauth_nonce%3DFWXxbP%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1491976910%26oauth_token%3DqyprdDXeKDQonYAz8O0OSnyewIsg34HjxZyH0X4Dk5dNE5LC%26oauth_version%3D1.0
I think it may be related to generating signature value. I have used PHP '$oauth->generateSignature()' function to generate the signature. It generates the value. But the authorization error still occurs. Please help me to solve the issue.
Here I am providing the codes that I am used.
$ar = array(
'authorization: OAuth oauth_consumer_key="'.OAUTH_CONSUMER_KEY.'",oauth_token="'.ACCESS_TOKEN_SECRET.'",oauth_signature_method="HMAC-SHA1",oauth_timestamp="'.$time.'",oauth_nonce="'.$randomvalue.'",oauth_version="1.0",oauth_signature="'.$signaturevalue.'"',
"cache-control: no-cache",
"content-type: application/json",
"Accept: application/json"
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://sandbox- quickbooks.api.intuit.com/v3/company/{{companyid}}/account",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{
\"AccountType\": \"Accounts Receivable\",
\"Name\": \"MyJobs\"
}",
CURLOPT_HTTPHEADER => $ar,
));
$response = curl_exec($curl);
This is the code I used for creating an account. I used following code to generate signature.
$oauth = new OAuth(OAUTH_CONSUMER_KEY,OAUTH_CONSUMER_SECRET);
$signature = $oauth->generateSignature('POST','https://sandbox-quickbooks.api.intuit.com/v3',$params);
In this case $params array defined as follows
$params = array(
'oauth_consumer_key' => OAUTH_CONSUMER_KEY,
'oauth_nonce' => $randomvalue,
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => $time,
'oauth_version' => '1.0',
'oauth_token' => ACCESS_TOKEN
);