Advisor Software Development Kit for PHP.
- PHP SDK
To install this package, use the following command:
composer require stormgeo/advisorcoreMake sure you're using php 7 or higher. Using earlier php versions may result in unexpected behavior or incompatibilities.
First you need to import the SDK on your application and instancy the AdvisorCore class setting up your access token and needed configurations:
require './vendor/autoload.php';
use StormGeo\AdvisorCore\AdvisorCore;
$advisor = new AdvisorCore('<your-token>');use StormGeo\AdvisorCore\Payloads\WeatherPayload;
$payload = new WeatherPayload([
'localeId' => 3477,
'variables' => ['temperature', 'precipitation']
]);
// requesting daily forecast chart image
$response = $advisor->chart->getForecastDaily($payload);
// requesting hourly forecast chart image
$response = $advisor->chart->getForecastHourly($payload);
// requesting daily observed chart image
$response = $advisor->chart->getObservedDaily($payload);
// requesting hourly observed chart image
$response = $advisor->chart->getObservedHourly($payload);
if (is_null($response->error)) {
$file = fopen('chart.png', 'wb');
fwrite($file, $response->data);
fclose($file);
} else {
print_r($response->error);
}use StormGeo\AdvisorCore\Payloads\ClimatologyPayload;
$climatologyPayload = new ClimatologyPayload([
'localeId' => 3477,
'variables' => ['precipitation']
]);
// requesting daily climatology data
$response = $advisor->climatology->getDaily($climatologyPayload);
// requesting monthly climatology data
$response = $advisor->climatology->getMonthly($climatologyPayload);
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}use StormGeo\AdvisorCore\Payloads\CurrentWeatherPayload;
$payload = new CurrentWeatherPayload([
'localeId' => 3477,
'variables' => ['temperature', 'precipitation']
]);
$response = $advisor->currentWeather->get($payload);
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}use StormGeo\AdvisorCore\Payloads\WeatherPayload;
$payload = new WeatherPayload([
'localeId' => 3477,
'variables' => ['temperature', 'precipitation']
]);
// requesting daily forecast data
$response = $advisor->forecast->getDaily($payload);
// requesting hourly forecast data
$response = $advisor->forecast->getHourly($payload);
// requesting period forecast data
$response = $advisor->forecast->getPeriod($payload);
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}$response = $advisor->monitoring->getAlerts();
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}use StormGeo\AdvisorCore\Payloads\WeatherPayload;
use StormGeo\AdvisorCore\Payloads\GeometryPayload;
use StormGeo\AdvisorCore\Payloads\LightningLitePayload;
use StormGeo\AdvisorCore\Payloads\RadiusPayload;
use StormGeo\AdvisorCore\Payloads\StationPayload;
$payload = new WeatherPayload([
'localeId' => 3477,
'variables' => ['temperature', 'precipitation']
]);
// requesting daily observed data
$response = $advisor->observed->getDaily($payload);
// requesting hourly observed data
$response = $advisor->observed->getHourly($payload);
// requesting period observed data
$response = $advisor->observed->getPeriod($payload);
$stationPayload = new StationPayload([
'stationId' => 'bWV0b3M6MDEyMEM5RkU6LTIzLjkzMDY4NDotNDYuNDg4NTQ4'
]);
// requesting station observed data
$response = $advisor->observed->getStationData($stationPayload);
$radiusPayload = new RadiusPayload([
'localeId' => 3477,
'radius' => 10000
]);
// requesting fire-focus observed data
$response = $advisor->observed->getFireFocus($radiusPayload);
// requesting lightning observed data
$response = $advisor->observed->getLightning($radiusPayload);
// requesting lightning observed details data
$response = $advisor->observed->getLightningDetails($radiusPayload);
$geometryPayload = new GeometryPayload([
'startDate' => '2024-11-28 00:00:00',
'endDate' => '2024-11-28 12:59:59',
'geometry' => '{"type": "MultiPoint", "coordinates": [[-41.88, -22.74]]}'
]);
$lightningLitePayload = new LightningLitePayload([
'startDate' => '2024-11-28 00:00:00',
'endDate' => '2024-11-28 12:59:59',
'geometry' => '{"type": "MultiPoint", "coordinates": [[-41.88, -22.74]]}',
'page' => 1,
'pageSize' => 10
]);
// requesting fire-focus observed data by geometry
$response = $advisor->observed->getFireFocusByGeometry($geometryPayload);
// requesting lightning observed data by geometry
$response = $advisor->observed->getLightningByGeometry($geometryPayload);
// requesting lightning lite observed data by geometry
$response = $advisor->observed->getLightningLite($lightningLitePayload);
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}use StormGeo\AdvisorCore\Payloads\StationsLastDataPayload;
$payload = new StationsLastDataPayload([
'stationIds' => ['station-id-1', 'station-id-2'], // optional
'variables' => ['temperature', 'precipitation'] // optional
]);
// requesting last data from stations
$response = $advisor->stations->getLastData($payload);
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}$payload = new PlanInfoPayload([
'timezone' => -3 # default timezone is 0 (UTC)
]);
$payloadForRequestDetails = new RequestDetailsPayload([
'page' => 1,
'pageSize' => 3
]);
$localePayload = new PlanLocalePayload([
'localeId' => 3477,
// You can also set Latitude/Longitude or StationId instead of LocaleId
]);
// requesting plan information
$response = $advisor->plan->getInfo($payload);
// requesting access history
$response = $advisor->plan->getRequestDetails($payloadForRequestDetails);
// requesting plan locale information
$response = $advisor->plan->getLocale($localePayload);
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}// Arbitrary example on how to define a schema
$schemaPayload = [
'identifier' => 'arbitraryIdentifier',
'arbitraryField1' => [
'type' => 'string',
'required' => 'true',
'length' => 125,
],
];
// Arbitrary example on how to upload data to parameters from schema
$parametersPayload = [
'identifier' => 'arbitraryIdentifier',
'arbitraryField1' => 'some text',
];
// requesting all schemas from token
$response = $advisor->schema->getDefinition();
// requesting to upload a new schema
$response = $advisor->schema->postDefinition($schemaPayload);
// requesting to upload data to parameters from schema
$response = $advisor->schema->postParameters($parametersPayload);
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}$payload = new StaticMapPayload([
'startDate' => '2025-07-21 00:00:00',
'endDate' => '2025-07-25 23:59:59',
'aggregation' => 'sum',
'dpi' => 100,
'title' => 'true',
'titlevariable' => 'precipitation',
'type' => 'periods',
'category' => 'observed',
'variable' => 'precipitation'
]);
$response = $advisor->staticMap->getStaticMap($payload);
if (is_null($response->error)) {
$file = fopen('staticMap.png', 'wb');
fwrite($file, $response->data);
fclose($file);
} else {
print_r('Error trying to get data!');
print_r($response->error);
}$payloadForListing = new StorageListPayload([
'page' => 1,
'pageSize' => 5
]);
$payloadForDownload = new StorageDownloadPayload([
'fileName' => 'Example.pdf',
'accessKey' => 'a1b2c3d4-0010'
]);
# requesting the files list
$response = $advisor->storage->listFiles($payloadForListing);
if (is_null($response->error)) {
print_r($response->data);
} else {
print_r("Error trying to get data!");
print_r($response->error);
}
# downloading a file from the list
$response = $advisor->storage->downloadFile($payloadForDownload);
if (is_null($response->error)) {
$file = fopen($payloadForDownload->fileName, 'wb');
fwrite($file, $response->data);
fclose($file);
} else {
print_r("Error trying to get file!");
print_r($response->error);
}
# downloading a file by stream
$response = $advisor->storage->downloadFileByStream($downloadPayload);
if (is_null($response->error)) {
$file = fopen($payloadForDownload->fileName, 'wb');
if (is_resource($response->data)) {
stream_copy_to_stream($response->data, $file);
} else {
fwrite($file, $response->data);
}
fclose($file);
} else {
print_r("Error trying to get file!");
print_r($response->error);
}use StormGeo\AdvisorCore\Payloads\TmsPayload;
$payload = new TmsPayload([
'istep' => '2025-01-24 10:00:00',
'fstep' => '2025-01-25 12:00:00',
'server' => 'a',
'mode' => 'forecast',
'variable' => 'precipitation',
'aggregation' => 'sum',
'x' => 2,
'y' => 3,
'z' => 4,
'timezone' => -3 # default timezone is 0 (UTC)
]);
$response = $advisor->tms->get($payload);
if (is_null($response->error)) {
$file = fopen('tile.png', 'wb');
fwrite($file, $response->data);
fclose($file);
} else {
print_r($response);
}use StormGeo\AdvisorCore\Payloads\PmtilesPayload;
$payload = new PmtilesPayload([
'mode' => 'forecast',
'model' => 'ct2w15_as',
'aggregation' => 'sum',
'variable' => 'precipitation',
'istep' => '2026-03-06 00:00:00',
'fstep' => '2026-03-06 01:00:00',
'maxZoom' => 4,
'timezone' => -3 # optional, default timezone is 0 (UTC)
]);
$response = $advisor->pmtiles->get($payload);
if (is_null($response->error)) {
$file = fopen('layer.pmtiles', 'wb');
fwrite($file, $response->data);
fclose($file);
} else {
print_r($response);
}You can also set headers to translate the error descriptions or to receive the response in a different format type. This functionality is only available for some routes, consult the API documentation to find out which routes have this functionality.
Available languages:
- en-US (default)
- pt-BR
- es-ES
Available response types:
- application/json (default)
- application/xml
- text/csv
Example:
use StormGeo\AdvisorCore\AdvisorCore;
$advisor = new AdvisorCore('invalid-token');
$advisor->setHeaderAccept('application/xml');
$advisor->setHeaderAcceptLanguage('es-ES');
$response = $advisor->plan->getInfo();
print_r($response->error);
// <response>
// <error>
// <type>UNAUTHORIZED_ACCESS</type>
// <message>UNAUTHORIZED_REQUEST</message>
// <description>La solicitud no está autorizada.</description>
// </error>
// </response>All the methods returns the same pattern:
{
"data": array|string|null,
"error": array|string|null,
}- localeId: string
- stationId: string
- latitude: float
- longitude: float
- timezone: int
- variables: array
- startDate: string
- endDate: string
- stationId: string
- layer: string
- timezone: int
- variables: array
- startDate: string
- endDate: string
- stationIds: array (optional)
- variables: array (optional)
- localeId: string
- stationId: string
- latitude: float
- longitude: float
- variables: array
- localeId: string
- stationId: string
- latitude: float
- longitude: float
- timezone: int
- variables: array
- localeId: string
- stationId: string
- latitude: float
- longitude: float
- startDate: string
- endDate: string
- radius: int
- startDate: string
- endDate: string
- radius: int
- geometry: string
- startDate: string
- endDate: string
- radius: int
- geometry: string
- page: int
- pageSize: int
- sources: array
- server: string
- mode: string
- variable: string
- aggregation: string
- x: int
- y: int
- z: int
- istep: string
- fstep: string
- timezone: int
- mode: string
- model: string
- aggregation: string
- variable: string
- istep: string
- fstep: string
- maxZoom: int
- timezone: int
- cmap: string
- dynamicElevation: string
- dynamicType: string
- dynamicVariable: string
- timezone: int
- localeId: int
- stationId: string
- latitude: string
- longitude: string
- page: int
- pageSize: int
- path: string
- status: string
- startDate: string
- endDate: string
- page: int
- pageSize: int
- startDate: string
- endDate: string
- fileName: string
- fileExtension: string
- fileTypes: string[]
- fileName: string
- accessKey: string
- startate: string
- endDate: string
- aggregation: string
- model: string
- lonmin: float
- latmin: float
- lonmax: float
- latmax: float
- dpi: int
- title: bool
- titlevariable: string
- hours: int
- type: string
- category: string
- variable: string