Hello @vicatcu,
I have a error, can you help me please. This is my code:
$jwt= getToken();
$url = ‘https://airqualityegg.wickeddevice.com/api/v2/most-recent/messages/device/my serial here’; // *** most recent mqtt upload
$result=getData($jwt, $url);
if($result== false){
echo 'Curl error: ’ . curl_error($ch);
}else{
echo $result;
}
//echo ($authorization = "Authorization: Bearer ".$jwt); //Prepare Autorisation Token
function getToken(){
$data = array(“name” => “my username”, “password” => “my password”);
$data_string = json_encode($data);
$ch = curl_init(‘https://airqualityegg.wickeddevice.com/api/v2/login’);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //timeout after 10 seconds
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'Content-Length: ’ . strlen($data_string))
);
$result = curl_exec($ch);
if($result== false){
$jwt = 'Curl error: ’ . curl_error($ch);
}else{
$data = json_decode($result, true); //Convert array in Json to Array in PHP
$jwt = $data[‘jwt’]; //print jwt value;
}
curl_close($ch);
return $jwt;
}
function getData($token, $ur) {
$numberOfSeconds = “10”;
$ch = curl_init();
$authorization = "Authorization: Bearer ".$token; //Prepare Autorisation Token
curl_setopt($ch, CURLOPT_URL, $ur);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0’);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’, $authorization )); //Inject Token into Header
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $numberOfSeconds); // connection timeout
curl_setopt($ch, CURLOPT_TIMEOUT, $numberOfSeconds); //data timeout
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //return the data transfer
curl_setopt($ch, CURLOPT_HEADER, 0); //No headers returned with result
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
When I run my code, function getToken() is very well. But function getData() have a error ({“error”:“my usernam is not authorized for mqtt path /most-recent/messages/device/my serial here”} )