abbrechen
Suchergebnisse werden angezeigt für 
Anzeigen  nur  | Stattdessen suchen nach 
Meintest du: 

To help get started.

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);

 

3 ANTWORTEN 3

@nerixs , Thanks a lot for sharing a sample code to support others getting started and doing their first API call!

Much appreciated!

Hi,

thanks alot for your sample code. But I am struggling with the easiest things... what exactly is the Client_ID? On my PT2 I can find S/N, ID, S/N from com module... nothing worked.

Do I need to register somewhere to get it?

 

Best regards,

Andi