I try to get data from https://climate-api.open-meteo.com service using Http::get method, but running request method getBody returns null, not array of data :
$response = Http::get('https://climate-api.open-meteo.com/v1/climate', [
'query' => [
'latitude' => $latitude,
'longitude' => $longitude,
'start_date' => $from->format('Y-m-d'),
'end_date' => $to->format('Y-m-d'),
]
]);
// RETURNS TRUE
\Log::info(varDump($response->successful(), ' -10 $response->successful()::'));
// RETURNS 200
\Log::info(varDump($response->getStatusCode(), ' -11 $response->getStatusCode()::'));
// RETURNS NULL
\Log::info(varDump(json_decode($response->getBody(), true), ' -12 $response->getBody()::'));
Making sample request like :
https://climate-api.open-meteo.com/v1/climate?latitude=40.4165&longitude=-3.7026&start_date=2023-07-09&end_date=2023-07-11&models=CMCC_CM2_VHR4&daily=temperature_2m_max
I got valid structure of data and do not see I got invalid data in $response->getBody() method ?
I think the fault lies in the Query string that you provide where you should pass in the following way:
$response = Http::get('https://climate-api.open-meteo.com/v1/climate', [
'latitude' => '40.4165',
'longitude' => '3.7026',
'start_date' => '2023-07-09',
'end_date' => '2023-07-11',
// 'models' => 'CMCC_CM2_VHR4',
// 'daily' => 'temperature_2m_max'
]);
In addition, there is no method called getBody
but it is called body
as Laravel illustrated here.