Hi @SorinB may be you can try my code below. As I said authorization is working fine getting the access token is working fine showing my profile is working fine everything else is not working <?php
// Initialization
//
$authorizeURL = "https://iam.viessmann.com/idp/v2/authorize";
$tokenURL = "https://iam.viessmann.com/idp/v2/token";
$client_id = "my_client_id"; // Change to your API Key
$code_challenge = "code_challenge"; // Change to your challende ig
$callback_uri = "http://localhost:4200/oauth-callback";
$user = "username"; // Change to your username
$pwd = "password"; // change to your password
$token = "not_used";
$refresh_token = "not_used";
/* */
// Code parameters
//
$url = "$authorizeURL?client_id=$client_id&code_challenge=$code_challenge&scope=IoT%20User%20offline_access&redirect_uri=$callback_uri&response_type=code";
$header = array("Content-Type: application/x-www-form-urlencoded");
$curloptions = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => "$user:$pwd",
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POST => true,
);
// Call Curl Code
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);
// Code Extraction
//
$matches = array();
$pattern = '/code=(.*)"/';
if (preg_match_all($pattern, $response, $matches)) {
$code = $matches[1][0];
} else {
exit("Erreur"."\n");
}
// Token Settings
//
$url = "$tokenURL?grant_type=authorization_code&code_verifier=$code_challenge&client_id=$client_id&redirect_uri=$callback_uri&code=$code";
$header = array("Content-Type: application/x-www-form-urlencoded");
$curloptions = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POST => true,
);
// Call Curl Token
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);
// Token extraction
//
$json = json_decode($response, true);
echo($response);
echo("\n");
$token = $json['access_token'];
/**/
// Read user data
//
$url = "https://api.viessmann.com/users/v1/users/me?sections=identity";
$header = array("Content-Type: application/x-www-form-urlencoded","Authorization: Bearer $token");
$curloptions = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
);
// Data Curl Call
//
$curl = curl_init();
curl_setopt_array($curl, $curloptions);
$response = curl_exec($curl);
curl_close($curl);
print_r(json_decode($response));
// get Installations-Id
//
$getURL='https://api.viessmann.com/iot/v1/equipment/installations/';
$headerRequest = array(
"Content-Type: application/x-www-form-urlencoded",
"Authorization: Bearer $token" //put here the name you have used for the AuthorizationTOKEN variable
);
$cURLConnection = curl_init();
curl_setopt($cURLConnection, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 7.01; Windows NT 5.0)");
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($cURLConnection, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER,true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $headerRequest);
curl_setopt($cURLConnection, CURLOPT_CONNECTTIMEOUT, 130);
curl_setopt($cURLConnection, CURLOPT_TIMEOUT, 130);
curl_setopt($cURLConnection, CURLOPT_URL,$getURL);
$apiResponse = curl_exec($cURLConnection);
$apiErr = curl_error($cURLConnection);
curl_close($cURLConnection);
$jsonResponse = json_decode($apiResponse, true);
print_r($jsonResponse);
print_r($apiErr);
?> THanks and regards Andreas
... Mehr anzeigen