These PHP bindings provide convenient access to the Octopus Energy Restful API for PHP applications.
Note: Accounts and Quotes endpoints are not implemented in this SDK as they are only available to Partner Organisations.
- An Octopus Energy account API Key (https://octopus.energy/dashboard/developer/)
- PHP >= 7.1
Install using composer
composer require markmorgan/octopus-energy
Before requesting data you will need to set your access credentials. This is done by initialising the OctopusEnergy Client:
$apiKey = 'my-octopus-apikey';
$client = new \OctopusEnergy\Client($apiKey);
The SDK has services for Product
, Meter
, and Industry
functions. The best place to look for all the functions available is within the services themselves.
Fetch all products (additional product filters available, see function signature):
$productsSearch = $client->products->all();
Fetch a specific product from its product code:
$productCode = 'VAR-21-09-29';
$product = $client->products->get($productCode);
Fetch info for a specific meter:
$mpan = 'YOUR MPAN NUMBER';
$meter = $client->meters->getElectricityMeter($mpan);
Fetch meter consumption:
$mpan = 'YOUR MPAN NUMBER';
$serialNumber = 'YOUR METER SERIAL NUMBER';
$consumptionSearch = $client->meters->getElectricityMeterConsumption(
$mpan,
$serialNumber
);
Filter the consumption between specific dates:
$fromDate = new \DateTime();
$fromDate->setTimestamp(1640995201); // Jan 1st 2022
$toDate = new \DateTime();
$toDate->setTimestamp(1643673601); // Feb 1st 2022
$pageNumber = 1;
$consumptionSearch = $client->meters->getElectricityMeterConsumption(
$mpan,
$serialNumber,
$pageNumber,
$fromDate,
$toDate
);
Fetch information about Grid Supply Points:
// fetch all grid supply point info
$gspSearch = $client->industry->getGridSupplyPoints();
// fetch grid supply point info for a postcode
$postcode = 'cf104uw';
$gspSearch = $client->industry->getGridSupplyPoints($postcode);
You can run PHPUnit against the library by running composer install and then running phpunit. Before doing so, you'll need to copy the example.phpunit.xml to phpunit.xml and change the environment variables for your API and meter details.