Hi, A simple practice to "get started". Regards, <?php
// Initialization
//
$authorizeURL = "https://iam.viessmann.com/idp/v2/authorize";
$tokenURL = "https://iam.viessmann.com/idp/v2/token";
$client_id = "Your_Customer_ID"; // API Key
$code_challenge = "47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU";
$callback_uri = "http://localhost:4200/";
$user = "Your_Email"; // The same as used for Vicare
$pwd = "Your_Password"; // The same as used for Vicare
// Code parameters
//
$url = "$authorizeURL?client_id=$client_id&code_challenge=$code_challenge&scope=IoT%20User&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);
$token = $json['access_token'];
// Read user data
//
$url = "https://api.viessmann.com/users/v1/users/me?sections=identity";
$header = array("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);
echo($response);
... Mehr anzeigen