I'm using Curl/PHP to get the token to communicate with QuickBooks Intuit API.
I'm able to summon the following response (a JSON Text error):
{"error":"invalid_client"}
This is how:
Starting Page
$parameters = array(
'client_id' => "my client id",
'scope' => "com.intuit.quickbooks.accounting",
'redirect_uri' => "http://localhost/redirect.php",
'response_type' => "code",
'state' => "RandomState"
);
$authorizationRequestUrl = 'https://appcenter.intuit.com/connect/oauth2?' . http_build_query($parameters);
header("Location: ".$authorizationRequestUrl);
Redirect endpoint (page) fetching access token
$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);
$client_id = "My Sandbox client id";
$client_secret = "My Sandbox secret";
$redirect_url = "http://localhost/redirect.php";
$access_token_url = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer";
$scope = "com.intuit.quickbooks.accounting openid profile email phone address";
$authorizationHeader = "Basic ".base64_encode($client_id.":".$client_secret);
$data = array(
'redirect_uri' => $redirect_url,
'grant_type' => 'authorization_code',
"code" => $queries["code"]
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $access_token_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
"Authorization" => $authorizationHeader,
"Accept" => "application/json",
"Content-Type" => "application/x-www-form-urlencoded",
"Connection" => "keep-alive"
),
));
$response = curl_exec($curl);
print_r($response); # see JSON Text error above
How can I prevent the invalid_client error code with the QuickBooks Intuit API?
I just figured out the issue. I was missing the certificate file in the request. It is mandatory or we get an
invalid_clienterror.